1
votes

I have a working ES2015 project, which I would like to migrate to TypeScript.

In my solution I am using ES2015 imports to import 3rd-pary modules (installed via npm) like this:

import {ClassXY} from 'moduleXY'

After setting up TypeScript in my project, the TypeScript compiler reports the following error:

error TS2307: Cannot find module 'moduleXY'

How can I get the above ES2015 import statement working in TypeScript?

I am looking for a solution other than installing the corresponding .d.ts declarations via typings... let's assume the module moduleXY is a library that does not distribute its own .d.ts declarations and there are no declarations available on DefinitelyTyped (or the declarations are outdated).

Must I create a stub for the type definitions of module moduleXY? How would I do that with minimal effort?

1

1 Answers

2
votes

if there are no typings for a module then you can just require it like a regular commonjs module

declare require:any;

const moduleXY:{
    classXY:any
} = require("moduleXY");

in a .ts file and make sure that file is included with your source in the Typescript compiler. you don't need to fully declare the module, and you will still benefit in places where you start adding types moving forward.