April 14, 2019
TypeScript is a tradeoff.
βI use typescript when I feel like having hours of migraines using 3rd party libraries and making sure I donβt have a single space or comma out of place! Works like a charm! Get a headache 10/10 times.β
-somebody on Reddit
TypeScript can do wonders for your code editorβs ability to help you with auto-completions, it can enforce contracts between different parts of your code base in the way documentation never could, and it can help a large team move faster.
It can also drive you to the point of madness when dealing with its increasingly pedantic compiler, especially when dealing with third party libraries that have incomplete, incorrect or conflicting types.
In general, itβs good to type as much as possible so you get the benefits TS offers. But how do you silence compiler warnings when itβs not your code and the upstream library just isnβt typed correctly?
You can add this to your codebase:
declare const annoyingLibrary: any;
And then the TypeScript compiler will stop complaining about annoyingLibrary
types.
Originally published at logicmason.com on April 14, 2019.
Top comments (2)
This was a really succinct and funny explanation of something I often have to google. These days I only used libraries that have type definitions because I donβt want to go through that issue above. But you made it more palatable! Thank you! :)
Thanks! I'm glad you found it helpful.