Clement
Clement

Reputation: 4811

Dealing with TS libraries without types or updated types

I'm a huge fan of static type, but there are many JS libraries that either don't have type definitions or have type definitions that are out of date and therefore cause compiler errors when you try to use a newer function.

Are there any known workarounds / practices in the TS community for overcoming this hurdle?

Upvotes: 4

Views: 1934

Answers (1)

kingdaro
kingdaro

Reputation: 12018

In the event of missing, incomplete, or broken types, IMO the best thing you can do is make a pull request to DefinitelyTyped.

In the meantime, here are some ways of solving issues locally:

  • Use a module declaration to declare types for missing modules
  • Use declaration merging to add missing types to classes or interfaces
  • Use your own custom types based off of a library's types with the appropriate corrections
  • Not recommended: do something like (lib as any).someMissingMethod(), or put a // @ts-ignore: explanation here comment above the line that errors, to temporarily suppress the error.

Upvotes: 4

Related Questions