TypeScript

Assigning a raw string to a template literal type in TypeScript

TypeScriptType ManipulationTemplate Literal Typesadvanced

What this snippet does

Template literal types enforce exact structural patterns, rejecting strings that don't match the specified literal and numeric placeholders.

Expected output

Compile Error: Type '"user-abc"' is not assignable to type '`user-${number}`'.

Why practise typing this

Typing type manipulation 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 →