Back to Cheat SheetsLanguage · Intermediate

TypeScript cheat sheet

Types, generics and config settings that keep an automation framework safe.

Types

Object type

type User = { id: string; age?: number };

Union / literal

type Env = 'dev' | 'qa' | 'prod';

Generic function

function first<T>(xs: T[]): T | undefined { return xs[0]; }

Utility types

Partial<User>, Pick<User,'id'>, Record<string, string>

Config

Strict mode

Catches most null/undefined defects

"strict": true

Path alias

"paths": { "@/*": ["./src/*"] }

Go beyond the reference

Book a free demo class and apply these commands on live project work.