typescript - 如何从 '.d.ts' 文件的命名空间中的其他库导入类型或接口(interface)?

标签 typescript namespaces typescript-typings typescript3.0 .d.ts

我正在制作在工作中使用 AWS SDK 的 TypeScript 库,.d.ts 文件中有错误。
'MyLib' only refers to a type, but is being used as a namespace here. ts(2702)
我正在使用 typescript@3.2.4,分配 types/tsconfig.json 输入Roots .
我试着搬家 import进入命名空间定义,但没有解决。
types/src/lib/mylib.d.ts

import { S3 } from "aws-sdk";

declare namespace MyLib {
  type DataType = S3.Body;
  class MyLib { }
}

src/lib/mylib.ts
export default class MyLib {
  constructor(data_type: MyLib.DataType) { }
  //                     ^^^^^ There is a that error here.
}

我预计该代码不会出错。

最佳答案

AWS 开发工具包将命名空间导出为 AWS ,所以我可以像 AWS.S3 一样使用.
types/src/lib/mylib.d.ts

declare namespace MyLib {
  type DataType = AWS.S3.Body;
  class MyLib { }
}

关于typescript - 如何从 '.d.ts' 文件的命名空间中的其他库导入类型或接口(interface)?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/54708986/

相关文章:

typescript - X 类型的参数不能分配给 Y 类型的参数。对象文字只能指定已知属性,并且 X 在类型 Y 中不存在

javascript - 导入别名 'theme'的循环定义

javascript - Angular:* ngFor在数组更改后不更新 View

javascript - ''router-outlet' 不是已知元素 - Angular

php - PHP命名空间混淆中的类路径等效

c++ - 使用命名空间时出错 - 类未声明

node.js - TypeScript 等待 Promise.all 并返回结果

windows-phone-7 - 在 Windows Phone 中重命名命名空间

typescript - 如何在接口(interface)声明中使用 PromiseConstructorLike 实例的原型(prototype)?

typescript - @types - 对象键的值数组