【问题标题】:Write definition files for modules exports a function returning a module为模块编写定义文件导出返回模块的函数
【发布时间】:2015-10-05 11:45:03
【问题描述】:

我最近正在为 node.js 模块“mongoose-bird”编写定义文件。该模块导出一个返回模块的函数。借助互联网上的指南,我写了这个:

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

但是我发现使用下面的代码,类型系统无法正常工作:

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

由于tsc 报告错误TS2503

error TS2503: Cannot find namespace 'mongoose'.

【问题讨论】:

    标签: node.js typescript tsd


    【解决方案1】:

    错误 TS2503:找不到命名空间“猫鼬”。

    因为您使用import 使您的文件成为一个模块(与全局命名空间断开连接)。

    推荐.d.ts 仅用于(挥手)声明,并仅使用相应的.ts 用于实施。

    【讨论】:

      猜你喜欢
      • 2017-06-13
      • 1970-01-01
      • 2014-07-24
      • 2021-12-23
      • 2016-12-30
      • 1970-01-01
      • 2016-03-21
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多