0

I'm totally stuck right now. Using Nodejs.

Having the following setup:

Compile -target ES5 --module commonjs

/def/mongoose.d.ts:

export = M;

declare module M {

    export class Collection {
        name:string;
    }
}

/model/users.ts:

///<reference path='..\def/mongoose.d.ts' />

export var foo:M.Collection;

Error: /model/users.ts(21,16): error TS2095: Could not find symbol 'M'.

Made it as simple as possible. I tried a lot but did not managed to access the class in the mongoose.d.ts

1 Answer 1

2

Instead of using a reference comment, you should import the module:

import M = require('./def/mongoose');
export var foo: M.Collection;

Usually, you would give the .d.ts file the same name (and location) as the .js file so the import statement would also load it at runtime.

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

4 Comments

This almost works. Problem now is, that it throws: Error: Cannot find module '../def/mongoose'. This is cause, there is no actual js file. I will see if it helps to create a .ts beside the d.ts to fix that.
When you are using CommonJS, you'll want the JavaScript file and the TypeScript definition file in the same location: /scripts/mongoose.d.ts and /scripts/mongoose.js
so having it as external module will not work at all?
Fixed it by moving the mongoose.d.ts to my project root.

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.