QutEcoacoustics / workbench-client

workbench-client: a client side browser application for interacting with acoustic workbenches
Other
8 stars 1 forks source link

Enable TypeScript strictNullChecks #2066

Open hudson-newey opened 1 year ago

hudson-newey commented 1 year ago

Describe the bug A common bug that keeps reoccurring is values being unexpectedly set to null or undefined. This can be fixed through TypeScript by enabling strictNullChecks.

"compilerOptions": {
    "strictNullChecks": true,
}

Expected behavior We should catch potential null and undefined errors at compilation rather than during runtime

Additional context We cannot push this change with another branch as it throws an enormous amount of errors with our existing code base (more than my terminal buffer size, so > 100 is my estimate)

Additional Note: We may want to enable "consistent-return": ["warn", { "treatUndefinedAsUnspecified": true }] in eslint. This will make it so each function requires a return type. This is not currently a requirement in our codebase.

Additionally, setting noImplicitAny: true would catch errors where we are currently able to bypass TypeScript error checking by using as any (which is currently prevalent in the codebase)

hudson-newey commented 1 year ago

We should also consider enabling @typescript-eslint/no-empty-function, @typescript-eslint/no-explicit-any, @typescript-eslint/no-inferrable-types, @typescript-eslint/prefer-as-const, and typescript strict: true mode so we can make our code base compatible Angular recommended es-lint settings

atruskie commented 1 year ago

Turn on each check separately, but I'm not opposed but ensure limited time. 1 hour per check.