如何在 tsconfig 中包含 Angular(不是 JS)类型,这样我就不必导入它们了?

How to include Angular (not JS) types in tsconfig so I don't have to import them?

过去几天我一直在研究如何在我的 .d.ts 文件中包含 Angular 类型,这样我就不必将我的类型导入到其他文件中。我尝试安装 @types/angular 但很快发现那是我不想要的 AngularJS。例如,如果我想定义这样的类型:

interface Foo {
   bar: EventEmitter<string>;
}

我必须导入 EventEmitter,现在必须导出 Foo,这会破坏 .d.ts 文件。现在这意味着它需要我将 Foo 导入到我想在其中使用它的任何文件中。相反,我想做这样的事情:

interface Foo {
   bar: angular.EventEmitter<string>;
}

希望这一切都有意义,我们将不胜感激任何帮助。

您可以使用以下语法内联导入:

import('@angular/core').EventEmitter<string>;

像这样:

interface Foo {
   bar: import('@angular/core').EventEmitter<string>;
}