0

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

2 Answers 2

1

lib.d.ts is a reserved filename for TypeScript internal library. Do not use it.

Sign up to request clarification or add additional context in comments.

2 Comments

Ok, it was just a example, my real file is not the same. I update my post.
I'm using TypeScript 2.0.0 (beta), and I encounter no error. Maybe you could give a try to this new release (npm install typescript@beta -g).
1

I solved using export = and import my_lib = require("my_lib"); syntax

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.