TypeScript Advanced
Advanced TypeScript type system features: generics, mapped types, conditional types, utility types, and strict mode.
- generic /dʒəˈnerɪk/
A type parameter written as <T> that makes a function, class, or type alias reusable across different types without sacrificing type safety.
"Our fetch wrapper is generic: function get<T>(url: string): Promise<T> — callers specify the expected response type and get full autocomplete."
- type parameter /taɪp pəˈræmɪtər/
Placeholder name such as T, K, or V in a generic declaration; can be constrained with extends to limit accepted types.
"function getProperty<T, K extends keyof T>(obj: T, key: K) ensures the key argument is a valid property name of the object type."
- mapped type /mæpt taɪp/
Type created by iterating over the keys of another type: { [K in keyof T]: SomeType }. Transforms every property systematically.
"We created a Nullable<T> mapped type: { [K in keyof T]: T[K] | null } to make every property of an API response nullable."
- conditional type /kənˈdɪʃənəl taɪp/
Type that resolves to one of two branches based on a condition: T extends U ? X : Y. Evaluated at compile time.
"IsArray<T> = T extends any[] ? true : false lets us branch the return type of a function based on whether the input is an array."
- template literal type /ˈtempleɪt ˈlɪtərəl taɪp/
A type formed from string literal combinations using template syntax: type EventName = `on${Capitalize<string>}`.
"We use a template literal type to enforce that all event handler prop names start with 'on': type Handler = `on${string}`."
- infer keyword /ɪnˈfɜː ˈkiːwɜːd/
Used inside a conditional type to extract and capture a type in a new type variable: ReturnType<T> uses infer R to capture the return type.
"type UnwrapPromise<T> = T extends Promise<infer U> ? U : T extracts the resolved type from a Promise."
- Partial<T> /ˈpɑːʃəl/
Built-in utility type that makes all properties of T optional; equivalent to { [K in keyof T]?: T[K] }.
"We use Partial<UserConfig> for the update endpoint so callers only need to send the fields they want to change."
- Required<T> /rɪˈkwaɪəd/
Built-in utility type that makes all properties of T required, removing any ? optional modifiers.
"After merging defaults, we cast to Required<Config> to tell TypeScript that every field is now definitely present."
- Pick<T,K> /pɪk/
Built-in utility type creating a new type with only the specified keys from T; useful for creating view models from domain types.
"Pick<User, 'id' | 'name' | 'email'> creates a lightweight type for the public API response without exposing hashed passwords or internal fields."
- Omit<T,K> /ˈɒmɪt/
Built-in utility type creating a new type that excludes the specified keys from T; the inverse of Pick.
"Omit<User, 'passwordHash' | 'internalId'> strips sensitive fields from the User type before serialising to JSON."
- Record<K,V> /ˈrekɔːd/
Built-in utility type creating an object type whose keys are of type K and values are of type V; clearer than index signatures for known key sets.
"Record<HttpMethod, RequestHandler> enforces that our router has a handler for every HTTP method in the HttpMethod union."
- type narrowing /taɪp ˈnærəʊɪŋ/
TypeScript's ability to refine a union type to a more specific type within a conditional block using typeof, instanceof, or discriminant properties.
"After if (typeof value === 'string') TypeScript narrows value to string inside the block, enabling string methods without a cast."
- discriminated union /dɪˈskrɪmɪneɪtɪd ˈjuːnjən/
A union of object types each sharing a common literal discriminant field; enables exhaustive type narrowing with switch or if-else.
"Our Result type is a discriminated union: { kind: 'ok', value: T } | { kind: 'err', error: Error } — switching on kind narrows the type fully."
- declaration merging /ˌdeklərˈeɪʃən ˈmɜːdʒɪŋ/
TypeScript feature allowing multiple interface declarations with the same name to be merged; used to extend third-party library types.
"We merge the Express Request interface to add a user property: declare global { namespace Express { interface Request { user: AuthUser } } }"
- strict mode /strɪkt məʊd/
tsconfig option "strict": true that enables all strict type-checks including noImplicitAny, strictNullChecks, and strictFunctionTypes.
"Turning on strict mode surfaced 40 implicit any errors and 15 places where we were not handling null — fixing them before production saved us from runtime crashes."
Quick Quiz — TypeScript Advanced
Test yourself on these 15 terms. You'll answer 10 multiple-choice questions — each shows a term, you pick the correct definition.
What does this term mean?