I want to use simple commonjs module in typescript and here are 3 files
original library:
//commonjs-export-function.js module.exports = function() { return 'func'; };
definition file:
//commonjs-export-function.d.ts declare function func(): string; export = func;
typescript that use it:
//main.ts import { func } from './commonjs-function'; console.log(func());
When I run tsc, I get this error:
tsc main.ts && node main.js main.ts(1,22): error TS2497: Module '"/Users/aleksandar/projects/typescript-playground/commonjs-function"' resolves to a non-module entity and cannot be imported using this construct.
a question has already been answered here too, but it does not work with typescript 2.0
How to write a typescript definition file for a node module that exports a function?
Aleksandar Djindjic
source share