我正在尝试在d.ts文件中创建一个命名空间接口,以便在使用相同命名空间的不同文件中使用,但我的IDE使用以下消息标记新文件中的接口:Cannot find name 'IProps'. ts(2304)
。
我在全球安装了Typescript 3.3.333333。我的VScode IDE状态栏显示Typescript 3.3.3。
/*
t.d.ts
*/
import {Map} from 'immutable';
declare namespace Configs {
export type Power = {
horse: number,
torque?: number
}
export interface IProps {
displacement: number,
options?: Map<string, any>,
power: Power
}
}
/*
index.ts
*/
/// <reference path="./t.d.ts" />
import {Map} from 'immutable';
declare namespace Configs {
export let props: IProps = { // Error - IDE here flags IProps
displacement: 3.2,
options: Map(),
power: {
horse: 560
}
}
}
在打字稿文档中的“模块和命名空间”页面上发生后,事实证明此用法不需要'declare'关键字。我从文件中删除了它,命名空间属性变得可用。 es6导出/导入和三重斜杠引用都不需要正确地发出和使用这些属性。我还将-isolateModules标志重置为其默认值,以允许正确编译跨文件名称空间。