survey-library
survey-library copied to clipboard
Add more type definitions
One of the big advantages of TypeScript is, as the name implies, it's type system. Using it will allow the compiler to identify bugs that are hard to spot for humans.
While looking into the file question (#4179) I found that many of the type hints simply use type any, this will shut up the compiler but also make it useless if we want it to check our logic for us.
Furthermore by adding type hints people reading the code (like me) will be able to identify what the expected structure of json objects in function arguments is.
Let me know if these kinds of PRs are useful / appreciated. And if you'd rather have one PR per file or a bunch of them.
With all of these the intentions are that nothing changes functionally, however some choices always have to be made.
For example a lot of functions take a parameter as type any but check if it is not falsy. For these I've assumed that the type is ExpectedType|null and that passing in things like 0 or false is not intended.
Assuming test coverage is good this should always be safe to merge at any point.
@SamMousa Thank you for the contribution. Your work is highly appreciated. Can you trigger your PR checks one more time? I believe your changes don't break anything and we'll merge this PR.