Address issues from TypeScript checking of javascript #1194
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Pull Request
Having another look at TypeScript checks now we have modernised our code.
Previous work: #1132
Reference: https://www.typescriptlang.org/docs/handbook/type-checking-javascript-files.html
Problem
Running TypeScript over
index.js
shows issues, most of which we would like to fix once we know. A few of them are things we can not avoid, like checking value of a property that may be undefined.Solution
Fix most issues by altering code and fixing JSDoc, suppress issues on five lines where we are checking properties which may not exist and the like (and no other way to tell TypeScript that we are doing it on purpose).
I used
undefined
rather thannull
for a couple of properties to match existing code:nestedError
to match existing TypeScript definitiondefaultValue
to match existing code (which tests for undefined)Depending on how much we like the TypeScript checking, could do less or more:
ts-check
so Visual Studio Code will check file when editing, happy to take it outnpm run lint
, happy to add it