将模块导入命名空间类

Import module to namespace class

本文关键字:命名空间 导入 模块      更新时间:2023-09-26

我需要将外部库导入命名空间类

应用:

namespace GlobNS {
   class A {}
}

模组:

import VSTS = require('ExtLib');
namespace GlobNS {
   class B extends ExtLib.ISMTH{
      prop1: string;
      prop2: number;
   }
}

ext-lib.d.ts:

declare module ExtLib {
   interface ISMTH {
      prop1: string;
      prop2: number;
   }
}

但是编译器说:"属性'ISMTH'在类型'ExtLib'上不存在。

另外,为什么它不起作用?打字稿游乐场

似乎你用extends关键字放错了implements。尝试将代码更改为:

class B implements ExtLib.ISMTH {
    prop1: string;
    prop2: number;
}

它应该有效。