3

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.

2
  • 1
    Something to try: bar: import('@angular/core').EventEmitter<string>; Commented Apr 22, 2020 at 12:51
  • Ughh, I can't believe it was that easy!! That seems to have done the trick. I really appreciate your help! Commented Apr 22, 2020 at 13:12

1 Answer 1

4

You can inline imports by using the following syntax:

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

Like this:

interface Foo {
   bar: import('@angular/core').EventEmitter<string>;
}
Sign up to request clarification or add additional context in comments.

1 Comment

It's not the prettiest solution but it gets the job done!

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.