我的项目是在Angular 7上开发的,我创建了一个定义文件,使其在整个应用程序中都可用,而不必导入类型:
// globals.d.ts
interface ISomethingA {
name: string;
age: number;
}
但当我尝试使用第三方库中的类型声明一个接口时,出现了一个问题:
// globals.d.ts
import { SomeTypeFromSomeWhere } from ‘some-library’;
interface ISomethingB {
propA: SomeTypeFromSomeWhere
}
应用程序仍然可以工作,但它会导致编译错误:Cannot find name 'ISomethingB’
。是否不鼓励导入基于第三方库的类型?任何有见地的人都将不胜感激!
发布于 2019-06-27 06:08:29
我像这样使用它,没有问题:
文件a.model.ts:
export interface SomeTypeFromSomeWhere {
prop: string;
}
文件b.model.ts:
import { SomeTypeFromSomeWhere } from './a.model';
interface ISomethingB {
propA: SomeTypeFromSomeWhere;
}
希望这能帮到你。
https://stackoverflow.com/questions/56784399
复制相似问题