How to import into Typescript without declaring a module

I have a bunch of auto-generated modules that I need to reference from my typescript files.

For instance,

  import test = require ('../ templates / test')

I am generating CommonJS modules with ES5 output. Therefore, I can not use amd-dependency (since this only works for amd-modules). And I also cannot manually declare a module with 1. it is auto-generated and 2. has a relative path.

Typescript 1.6 is currently displaying a "Cannot find module" error message. How to make it suppress this error and import?

+5
source share
2 answers

How to make it suppress this error and import

If you are sure that the require statement is valid and wants to disable type checking during import, you can simply use node.d.ts and do:

 var test = require('../templates/test') 

i.e. just use var instead of import .

+7
source

If you want to use TypeScript import (this is only ES6 import), you can use this:

 import * as test from '../templates/test'; 

and then call your API as follows:

 let foo = test.MY_API; 
0
source

All Articles