【发布时间】:2021-03-08 12:35:52
【问题描述】:
我是 TypeScript 的新手,我只想问一下(位置)来自另一个模型 TypeScript 的代码,因为
全部在模型文件夹中:
export interface Group {
name: string;
opportunities: Opportunity[];
}
opportunity.model.ts
export interface Opportunity {
name: string;
}
这是我company.model.ts在模型文件夹中的内容
export interface Company {
companyName: string;
position: opportunity; // my question is here? what should I put here,
// because the content of position is the
// opportunity which is like a dropdown
contactNumber: number;
}
谢谢。我不知道我在做什么。
【问题讨论】:
-
在
Company中,为什么opportunity是小写的?案件很重要。 -
您没有定义称为机会的类型。 Typescript 会进行类型检查,并且有机会!= Opportunity ... 这能编译吗?
-
我不知道该在“机会”中放什么,因为该位置的内容来自另一个模型打字稿。
-
例如,当使用枚举时,您只需像这样导入它来自的实体 ``` import {Relation} from "./entities/Family" export interface Family{ 关系:关系;}```
标签: javascript typescript interface