首页 > 解决方案 > Angular 使用带有命名空间的接口

问题描述

我正在使用带有类型脚本 2.7.2 的 Angular 6。我在单独的文件中创建了模型接口,但具有相同的命名空间:

模型1.ts:

namespace Api {
    export interface Model1 {
       field1: string;
       field2: number;
    }
}

模型2.ts

namespace Api {
    export interface Model2 {
       field1: string;
       field2: number;
       field3: Api.Model1;  // this caused the error
    }
}

使用接口 Model1 到接口 Model2 会导致错误。

(TS) Namespace 'Api' has no exported member 'Model1'.

这样做的正确方法是什么?

标签: angulartypescriptinterface

解决方案


推荐阅读