Type-only import specifiers by andrewbranch · Pull Request #45998 · microsoft/TypeScript (original) (raw)

Follow-up feature to #44619, allows

import { SomeComponent, type SomeProps } from "./component"

Emit behavior

This means that under default settings,

import { type SomeProps } from "./component";

gets erased from the JS entirely, because default settings remove any import declarations that can be removed. But under --importsNotUsedAsValues=preserve (or error), the same code is emitted as

import {} from "./component";

because the type keyword on the imports specifier does not indicate that there is no runtime module dependency on "./component".

Auto-imports behavior

As discussed in #44619, the combination of --isolatedModules and --preserveValueImports requires that exported symbols that have no value meaning (i.e., they’re purely types or uninstantiated namespaces) or are imported/exported with a type-only import/export somewhere earlier in the chain be imported with a type-only import so transpilers can know to drop those import specifiers. Obviously, auto-imports had to be updated to account for this when importing types or already-type-only symbols. This PR includes the changes to make working under those settings manageable, though there are further experience enhancements I need to investigate. Here’s a non-exhaustive summary of what happens now:

Future improvements to look into:

Other follow-up work