TypeScript

Attempting to use a type-only import as a value in TypeScript

TypeScriptAdvanced Modulesimport type vs importadvanced

What this snippet does

Because 'import type' is erased at runtime, using it as a value (like instantiating a class) causes a runtime ReferenceError or compile error.

Expected output

Compile Error: 'Config' cannot be used as a value because it was imported using 'import type'.

Why practise typing this

Typing advanced modules code builds muscle memory for the symbols and indentation TypeScript uses most, which prose-based typing tests never cover. DevType measures your words per minute and accuracy on this snippet and tracks the individual characters you mistype, so later lessons can target them.

More TypeScript practice

Browse all TypeScript snippets →