4 ms·
I basically do two things to make sure type checking doesn't slow me down: 1) Use emitOnly: true. This means that if your code has type errors, it still compil
by AriaMinaei 8y ago
I basically do two things to make sure type checking doesn't slow me down:
1) Use emitOnly: true. This means that if your code has type errors, it still compiles. And you can fix the type error later.
2) Never use any directly. Not all anys are equal. Some are there because you don't have the time to figure out a proper type annotation. Others are there because you can express a proper annotation, but think that it's just not worth the effort. And some anys are there because the type system is not capable of expressing the type you have in mind.
What you want to do is to clearly annotate your intention when you're typing something as any. So what I do is to simply disallow directly using any, and instead, use a few global type aliases that better communicate my intention:
type $FixMe = any // Fix this type, preferably before accepting the PR
type $IntentionalAny = any // This `any` is intentional => never has to be fixed
type $Unexpressable = any // TS cannot express the proper type atm
I often put these aliases in a defs.d.ts file and use them instead of any.
- draw_down 8y agoI'll agree on not using `any`, but type errors should cause the build to fail. Otherwise what is the type checker even for?