Search code examples
angulartypescripttsconfig

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


I've been spending the past couple of days trying to figure out how to include Angular types in my .d.ts files so I don't have to import my types into other files. I tried installing @types/angular but quickly discovered that's for AngularJS which I don't want. For instance, if I want to define a type like this:

interface Foo {
   bar: EventEmitter<string>;
}

I would have to import EventEmitter and now have to export Foo which breaks the .d.ts file. Now that means it requires me to import Foo into whatever file I want to use it in. Instead, I would like to do something like this:

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

Hopefully this all makes sense and any help would be greatly appreciated.


Solution

  • You can inline imports by using the following syntax:

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

    Like this:

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