DEV Community

Mark
Mark

Posted on • Originally published at logicmason.com

1 2

How to make TypeScript shut up about that library

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.

TypeScript errors

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;
Enter fullscreen mode Exit fullscreen mode

And then the TypeScript compiler will stop complaining about annoyingLibrary types.

Originally published at logicmason.com on April 14, 2019.

Please leave your appreciation by commenting on this post!

It takes one minute and is worth it for your career.

Join now

Top comments (2)

Collapse
 
cubiclebuddha profile image
Cubicle Buddha

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! :)

Collapse
 
logicmason profile image
Mark

Thanks! I'm glad you found it helpful.

Image of Datadog

Create and maintain end-to-end frontend tests

Learn best practices on creating frontend tests, testing on-premise apps, integrating tests into your CI/CD pipeline, and using Datadog’s testing tunnel.

Download The Guide

👋 Kindness is contagious

Explore a sea of insights with this enlightening post, highly esteemed within the nurturing DEV Community. Coders of all stripes are invited to participate and contribute to our shared knowledge.

Expressing gratitude with a simple "thank you" can make a big impact. Leave your thanks in the comments!

On DEV, exchanging ideas smooths our way and strengthens our community bonds. Found this useful? A quick note of thanks to the author can mean a lot.

Okay