You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
We currently only have strictNullChecks enabled, which is the least we can do when using TypeScript. It already guards against assigning null or undefined to objects:
interfaceFoo{a: stringb: number}consta: Foo=null;// Error thanks to strictNullChecks.
But there are other checks that are currently not enabled and that let some potential issues slip into the code base, e.g.:
interfaceBar{method(a: Meh|number): string}classBazimplementsBar{// Here TypeScript should fail but doesn't because strictFunctionTypes is not enabled.method(a: string): string{returna;}}constbar: Bar=newBaz();constresult: string=bar.method({a: 'meh',b: 2});// `result` isn't a string here, but TypeScript doesn't know.
There's also strictPropertyInitialization that tries to enforce proper initialization of class fields. If not done at construction time, then the field must be declared as potentially undefined, because it will be undefined until some later point in time. This check has to be the most annoying one in our code base as we are using Inversify's property injectors:
@injectable()classQux{
@inject(Something)protectedsomething: Something;// TypeScript will complain here because not set at construction time.}
This issue can be avoided by telling TypeScript to ignore checking those fields by adding a !:
@injectable()classQux{
@inject(Something)protectedsomething!: Something;// TypeScript is happy.}
Enabling this check will incur a LOT of changes but going forward it will help catch mistakes where a field might be left undefined but is not typed as such.
The text was updated successfully, but these errors were encountered:
We currently only have
strictNullChecks
enabled, which is the least we can do when using TypeScript. It already guards against assigningnull
orundefined
to objects:But there are other checks that are currently not enabled and that let some potential issues slip into the code base, e.g.:
There's also
strictPropertyInitialization
that tries to enforce proper initialization of class fields. If not done at construction time, then the field must be declared as potentially undefined, because it will be undefined until some later point in time. This check has to be the most annoying one in our code base as we are using Inversify's property injectors:This issue can be avoided by telling TypeScript to ignore checking those fields by adding a
!
:Enabling this check will incur a LOT of changes but going forward it will help catch mistakes where a field might be left undefined but is not typed as such.
The text was updated successfully, but these errors were encountered: