1

I am using Typescript 2.1. I am trying to install an npm package that doesn't have typings (reactable).

If I do:

import * as Reactable from 'reactable' typescript complains that cannot find this module.

If I do:

const Reactable = require('reactable') typescript complains that require is forbidden.

If I do the weird syntax that suggested in another post:

import Reactable = require('reactable'); typescript complains that import assignment cannot be used to target es2015 modules.

Is there any way to import npm packages that do not have typings?

Vickyexpert
  • 3,147
  • 5
  • 21
  • 34
Avraam Mavridis
  • 8,698
  • 19
  • 79
  • 133
  • Is this a duplicate of [TS2304](http://stackoverflow.com/questions/31173738/typescript-getting-error-ts2304-cannot-find-name-require)? Have you tried `declare var require: any`? – James Taylor Nov 29 '16 at 06:09

1 Answers1

2

You'll need to declare something about what you're using. For example

declare module "reactable" {
    interface ReactableProps {
        ....
    }

    interface ReactableState {
        ....
    }

    class reactable extends React.Component< ReactableProps, ReactableState> { }
}

You can start with just what you're using and need the IDE to support, and slowly add things up.

You can check the Writing Declaration Files for more info on how to do so.

solarhell
  • 172
  • 8