Consider using strict
TypeScript option
#159
Replies: 1 comment 2 replies
-
I use strict option in some of my other projects and cannot say that it brings much value in any of them. All it does is forcing me to add null to my types, e.g. in your example it will be noImplicitAny is fine but won't work because of components that support |
Beta Was this translation helpful? Give feedback.
-
Consider whether enabling strict option in tsconfig would be possible. Given the size of the codebase it is enormous effort, however long term it provides great benefits. Strict option enables bunch of additional checks which aren't enabled by default because of backwards compatibility, but the option is recommended to be set to true.
strictNullChecks
One of the most important checks nowdays is strictNullChecks, especially for libraries because it propagates to consumers code through typings. If I want to use
useControlled
hook in my codebase with strictNullChecks enabled I get following errors:This check also forces developers think about
null
andundefined
values at all times. It can be annoying at first, but from my experience it avoids a lot of bugs and gives clear intent on whether property/parameter/variable is supposed to be able to contain null or undefined values or not.noImplicitAny
Other checks enabled by
strict
are good to have as well, for instance noImplicitAny which currently caches a lot ofany
uses - some of which seem to be only thanks to TS not being able to look too far into generics like herewhich I don't think we can realistically handle properly, but it's still nice to be alerted and knowingly work around it.
Beta Was this translation helpful? Give feedback.
All reactions