Reputation: 6859
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 files
import { NotificationContainer, NotificationManager } from 'react-notifications';
can't find typings for react-notifications
Upvotes: 0
Views: 330
Reputation: 29824
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
Upvotes: 1
Reputation: 116674
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):
declare module "react-notifications" {
const NotificationContainer: any;
const NotificationManager: 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.
Upvotes: 2