I have a simple file types.ts
that defines some types:
export interface MyInterface {
// ...
}
export const enum MyEnum {
// ...
}
export type MyType = {
// ...
}
I have read about the new feature import type
for the latest typescript here. As far as I understand, it is meant to fix specific problems which seem mostly to happen when importing from .js
files.
I can import my types with both import
and import type
statements. Both seem to work equally fine. The question is should I prefer import type
because it is more explicit and helps me to avoid some theoretical edge-case problems or can I just use import
for simplicity and rely on import elision
to remove these from compiled code?
In other words: are there any benefits of using import type
here or should it rather be used for specific cases to work around import elision
shortcomings?
import { type SomeType, someFunction, SomeClass }
is for importing type less verbosely. typescript 4.5 has type modifiers on import names. doc – Aquila