【发布时间】:2020-03-18 11:03:22
【问题描述】:
我有一个类型定义文件,其中我的应用程序的所有 dto 对象都暴露在全局范围内。
DtosGenerator.d.ts
declare module MyApp.Rest.Dto {
interface IAJsonDto {
}
}
declare module MyApp.Rest.Dto.Post {
interface ITest1PostDto extends MyApp.Rest.Dto.IAJsonDto {
code: string;
}
interface ITest2PostDto extends MyApp.Rest.Dto.IAJsonDto {
id: number;
}
interface ITest3PostDto extends MyApp.Rest.Dto.IAJsonDto {
id: number;
}
....
}
并通过以下方式消费。
file1.service.ts
import ITest3PostDto = MyApp.Rest.Dto.Post.ITest3PostDto;
我的应用程序是基于 Angular 框架构建的,我刚刚分别完成了从 Angular(8)、Typescript(3.5.3) 到 Angular9、Typescript(3.6.4) 的迁移。在迁移之前,对 Dto 对象的消耗没有产生任何错误,一切看起来都很正常。迁移后,当应用程序在手表模式下运行时,
ng build --extractCss=true --watch 命令,控制台输出'Cannot find namespace 'MyApp'。当我添加
/// <reference path="../../../../DtosGenerator.d.ts" />
在文件顶部不再产生错误。有没有办法在不添加引用路径的情况下保持我的代码在迁移之前的样子。
谁能告诉我怎么回事?
【问题讨论】:
标签: angular typescript angular-cli