Skip to main content

TypeScript analyzer

TypeScript Import Discipline

Surfaces import-statement hygiene: value imports used only as types, namespace imports of project modules, and barrel files.

patterns ts-import-discipline

TypeScript Import Discipline

Surfaces import-statement hygiene: value imports used only as types, namespace imports of project modules, and barrel files.

Imports are a file's declared dependencies, and TypeScript lets them say more than "this module": import type says a binding exists only for the type checker, and named imports say which exports are used. This analysis reports imports that leave that unsaid: a value import whose every use is a type position, a namespace import of one of the project's own modules, and a file that is mostly re-exports.

It reports only what the file proves. A binding counts as type-only when no use needs the value: a class in an extends clause, a constant used as a parameter default, a decorator and a typeof x expression all need it, and converting those to import type would not compile. Namespace imports of modules whose documentation prescribes import * as (Node built-ins, vscode, and a short list of libraries) are the idiom and are not reported. These are style findings: TypeScript already drops an import that is used only as a type, so nothing here claims a runtime cost.

Severity guide

info
Import style could state more: a type-only import, a named import, or a narrower barrel.
warning
Not currently emitted by this analysis.
critical
Not currently emitted by this analysis.

Remediation

Add `import type` where bindings are types only, prefer named imports over namespace imports, and reduce barrel-file indirection.

Add import type where bindings are types only, prefer named imports over namespace imports, and reduce barrel-file indirection.

Documentation