【问题标题】:TypeScript model export interfaceTypeScript 模型导出接口
【发布时间】: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


【解决方案1】:

如果您觉得您正在寻找这样的东西,则无需更多上下文:

export interface Group {
        name: string;
        opportunities: Opportunity[];
     }
    
    
    
     export interface Opportunity {
        name: string;
     }
    
    
    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;
    }

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2015-08-23
    • 2018-07-25
    • 2012-11-14
    • 2020-03-06
    • 2021-08-09
    • 2017-05-31
    • 1970-01-01
    • 2016-12-26
    相关资源
    最近更新 更多