Reputation: 2036
I try to create a typescript declaration file for a sample JS library
my_lib.js :
function f1(a, b) {
return a + b;
}
function f2(a, b) {
return a - b;
}
module.exports = {
f1: f1,
f2: f2
}
my_lib.d.ts
declare module 'my_lib' {
function f1(a: number, b: number): number;
function f2(a: number, b: number): number;
export default {
f1: f1,
f2: f2
}
}
A typescript file try to used the library with
import my_lib from 'my_lib';
I have this error
error TS2656: Exported external package typings file 'C:/.../my_lib.d.ts' is not a module. Please contact the package author to update the package definition.
Any idea? Thanks
Upvotes: 0
Views: 2646
Reputation: 2036
I solved using export =
and import my_lib = require("my_lib");
syntax
Upvotes: 1
Reputation: 188
lib.d.ts is a reserved filename for TypeScript internal library. Do not use it.
Upvotes: 1