3 ms·
One of the biggest mistakes that I see devs making is caring too much about making TypeScript happy when they know it doesn't really matter. There are a lot of
by rattray 4y ago
One of the biggest mistakes that I see devs making is caring too much about making TypeScript happy when they know it doesn't really matter.
There are a lot of cases where it's totally reasonable/rational and honestly fairly safe to just throw in a well-scoped "any" cast, a `// @ts-expect-error` comment, etc.
If you know what you're trying to do, and TS isn't understanding, sometimes it's just a lot more expedient to tell it to shut up and listen to you.
Of course, sometimes you're wrong, and you don't want unsafety to leak, so it does require a fair amount of experience and judgement to do responsibly.
- josephcsible 4y agoThis feels like telling Haskell developers that they should use unsafePerformIO and unsafeCoerce more.
- rattray 4y agoIt's much more like reminding TS developers that Go developers have to use `interface{}` all the time, because some types are actually hard for compilers/typecheckers to deal with.
- DangitBobby 4y agoMaybe? Occasionally telling ts to shut up or lying about types is better than not using it because you have a hard time getting 100% type correctness.
- dmak 4y agoTIL: `@ts-expect-error` I've been using ignore a lot and leaving a comment.