Verbatim module syntax
Concept and boundary
With verbatimModuleSyntax, type-only imports are erased and ordinary import/export syntax is retained rather than automatically rewritten to another module system. Use a compatible module format and explicitly mark type-only bindings.
Accepted project
Create a fresh folder with exactly these files. Use TypeScript 5.8.3 and Node.js 22.16.0. Package stubs under node_modules are local teaching fixtures, not installed dependencies.
import type {Item} from "./dep.js"; import {n} from "./dep.js"; const x:Item={n}; console.log(x.n);package.json
{ "type": "module"}tsconfig.json
{ "compilerOptions": { "strict": true, "target": "ES2022", "module": "NodeNext", "moduleResolution": "NodeNext", "moduleDetection": "force", "skipLibCheck": true, "noEmitOnError": true, "types": [], "verbatimModuleSyntax": true }, "include": [ "**/*" ], "exclude": [ "node_modules", "dist", "build", "cache" ]}From the project root run: tsc -p tsconfig.json --pretty false.
Compilation succeeds (exit 0).
Run node main.js. Expected stdout:
5main.js exists.
Contains "import { n }".
Does not contain "Item".
Rejected project — diagnosis
Intentionally rejected variant. Do not execute it.
Use a fresh copy of the accepted project, changing only the files shown below.
import {Item,n} from "./dep.js"; const x:Item={n}; console.log(x.n);From the project root run: tsc -p tsconfig.json --pretty false.
Expected compiler diagnostic: TS1484
No runtime execution is required for this check.
Item is a type and must be imported with a type-only modifier under this option. Restore the accepted configuration/source to compare the result.
Practice and recap
Inspect main.js and verify that only n remains imported.
Check Your Understanding
Solidify your learning with the interactive assessment directly below this lesson.
Concept Quiz & Questions
Verbatim module syntax — knowledge check
Check the concept, interpret the tested project result, and diagnose a rejected configuration or source.
Which statement correctly describes Verbatim module syntax?
Using the complete accepted project and the exact command in the lesson, which result is expected?
import type {Item} from "./dep.js"; import {n} from "./dep.js"; const x:Item={n}; console.log(x.n);Why does the rejected project fail under its stated configuration?
import {Item,n} from "./dep.js"; const x:Item={n}; console.log(x.n);