0

I am recently writing definition files for node.js module "mongoose-bird". This module exports a function returning a module. With guides on the internet, I wrote this:

declare module "mongoose-bird" {
  export = () => MongooseAsync;
  module MongooseAsync {
...

But I found that with the following code, the type system cannot work properly:

import mongoose_bird = require('mongoose-bird');
var mongoose = mongoose_bird();
...
export interface IUser extends mongoose.Document {

Since tsc reports error TS2503

error TS2503: Cannot find namespace 'mongoose'.
小傅Fox
  • 3
  • 2

1 Answers1

0

error TS2503: Cannot find namespace 'mongoose'.

Because you made your file a module (disconnected from the global namespace) by using import.

Recommend a .d.ts for (a hand wavy) declaration only with a corresponding .ts for implementation.

basarat
  • 261,912
  • 58
  • 460
  • 511