typescript - 使用来自另一个文件的 Typescript 类型定义

标签 typescript typescript-typings

我有一个 Typescript 定义 ./src/@types/moduleA/moduleA.d.ts 其中包含:

declare module 'moduleA' {
  export interface Transaction {...}
}

我想在另一个类型定义文件 ./src/@types/moduleB/moduleB.d.ts 中使用它,如下所示:

///<reference path="../moduleA/moduleA.d.ts" />

declare module 'moduleB' {
  export class MyClass {
    constructor(private transaction: Transaction) {}
  }
}

但我收到了 Cannot find name 'Transaction'.ts。 为什么?我是否也必须导入它?

谢谢

最佳答案

所以对于任何正在搜索的人:

只应使用 import { Transaction } from 'moduleA';

关于typescript - 使用来自另一个文件的 Typescript 类型定义,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/60447175/

相关文章:

angularjs - 带有 TypeScript 2.x、@types 和 SystemJS 的 Angular 1.x - 使用全局类型

reactjs - 不能在一行中设置三个元素

javascript - typescript 命名空间引用不起作用

json - 来自同一用户的数组周围的 Angular6 Div

typescript - 如何在 Vue3 中使用 TypeScript 为 ref 定义类型(绑定(bind)模板)?

规范化数据的 TypeScript 类型或接口(interface)

javascript - typescript 打字封装

typescript - 在多个 TypeScript 文件中声明和使用相同的命名空间

Angular 2 - 如何访问回调中的变量并将其显示在 View 上

javascript - ReactJS:一个数字输入可以以多个 '0' 结束