Is It Necessary To Have Typing/definiton Files For Every Js Library You Use In Typescript?
Is it necessary to have typing for every JS library you use in typescript? if not, then how to get rid of errors and make use of a library which doesn't have available definition
Solution 1:
It's not necessary. For your example, you create a file react-notifications.d.ts
(you can call it anything you like as long as the extension is .d.ts
but it makes sense to name it consistently):
declaremodule"react-notifications" {
constNotificationContainer: any;
constNotificationManager: any;
}
That's a near-minimal starting point. But you could go a little further and improve on those any
declarations. They are a temporary cop-out.
Solution 2:
An alternative to @Daniel Earwicker answer, as long as you are in a commonJS environment (and I guess you are using webpack) is to simply require
the library using node require
const rn = require('react-notifications')
then use rn.NotificationContainer
directly or import NotificationContainer = rn.NotificationContainer
Post a Comment for "Is It Necessary To Have Typing/definiton Files For Every Js Library You Use In Typescript?"