Home / Code typing practice / TypeScript

Free code typing practice

TypeScript Typing Practice

Free TypeScript typing practice: type real TS with interfaces, generics <T>, union types and async functions. Build speed on angle brackets, colons and pipes.

TypeScript adds a layer of symbols on top of JavaScript: type annotations after colons, generics in angle brackets, union types with the pipe |, and optional properties with ?. Practising it trains reaches that plain JS never asks for.

The snippets cover interfaces, generic functions, Map types, union string literals and typed async calls, the everyday patterns of Angular, React and Node.js projects in TypeScript.

TypeScript code you will type

Each session picks from these, in random order. Line breaks are shown as single spaces.

interface User { id: number; name: string; email?: string; }
function first<T>(items: T[]): T | undefined { return items[0]; }
const byId = new Map<number, User>(users.map(u => [u.id, u]));
type Status = 'idle' | 'loading' | 'done'; let state: Status = 'idle';
export async function getUser(id: number): Promise<User> { const r = await fetch(`/api/users/${id}`); return r.json(); }

Symbols to watch

:< >|?=>{ }[ ]`

Not sure which finger to use? See the programming symbols finger chart.

Tips for typing TypeScript faster

  • The pipe | is Shift and backslash: hold left Shift and reach up with your right little finger.
  • Generics like Map<number, User> need a quick Shift: practise the < > pair until it's one motion.
  • Put a space after each colon in a type annotation as you type; it keeps your rhythm steady.

Frequently asked questions

Is TypeScript harder to type than JavaScript?

A little, because of the type annotations: more colons, angle brackets and pipes. The practice is worth it if you write TypeScript every day.

Should I practise JavaScript or TypeScript?

Practise the one you use at work. If you use both, alternate: TypeScript trains every symbol JavaScript uses, plus the type syntax.

Practise typing other languages

All code typing practice