Comprehensive TypeScript guidance covering compiler configuration, advanced types, utility types, type guards, strict mode workflows, and documentation patterns; use when configuring tsconfig, designing complex generics, making illegal states unrepresentable, fixing type errors, or writing testable and maintainable type-safe APIs.
Overall
score
99%
Does it follow best practices?
Validation for skill structure
Removes types from T that are assignable to U.
type AllColors = 'red' | 'green' | 'blue' | 'yellow';
type PrimaryColors = Exclude<AllColors, 'yellow'>;
// Type: 'red' | 'green' | 'blue'
type NonBlueColors = Exclude<AllColors, 'blue' | 'green'>;
// Type: 'red' | 'yellow'type Exclude<T, U> = T extends U ? never : T;How it works: Distributive conditional type - checks each member of T union.
Filter Union Types
type Status = 'pending' | 'approved' | 'rejected' | 'cancelled';
type ActiveStatus = Exclude<Status, 'cancelled'>;
// 'pending' | 'approved' | 'rejected'
function processActiveOrder(status: ActiveStatus) {
// status cannot be 'cancelled'
}Remove null/undefined
type MaybeString = string | null | undefined;
type DefiniteString = Exclude<MaybeString, null | undefined>;
// Type: string
// Note: NonNullable does the same thing
type DefiniteString2 = NonNullable<MaybeString>;
// Type: stringFilter by Type
type Mixed = string | number | boolean | null | undefined;
type OnlyPrimitives = Exclude<Mixed, null | undefined>;
// string | number | boolean
type OnlyStringsAndNumbers = Exclude<Mixed, boolean | null | undefined>;
// string | numberRemove Function Types
type Value = string | number | (() => void) | (() => string);
type NonFunction = Exclude<Value, Function>;
// string | numberExtracts from T only types that are assignable to U (opposite of Exclude).
type AllColors = 'red' | 'green' | 'blue' | 'yellow';
type WarmColors = Extract<AllColors, 'red' | 'yellow' | 'orange'>;
// Type: 'red' | 'yellow' (orange doesn't exist in AllColors)type Extract<T, U> = T extends U ? T : never;Filter to Specific Types
type Mixed = string | number | boolean | null;
type StringOrNumber = Extract<Mixed, string | number>;
// string | number
type OnlyString = Extract<Mixed, string>;
// stringExtract Function Types
type Value = string | number | (() => void) | (() => string);
type OnlyFunctions = Extract<Value, Function>;
// (() => void) | (() => string)Extract Object Types
type Mixed = string | number | { name: string } | { id: number };
type OnlyObjects = Extract<Mixed, object>;
// { name: string } | { id: number }Pattern Matching with Strings
type Events = 'onClick' | 'onHover' | 'onFocus' | 'handleClick' | 'handleSubmit';
// Extract events starting with 'on'
type OnEvents = Extract<Events, `on${string}`>;
// 'onClick' | 'onHover' | 'onFocus'
type HandleEvents = Extract<Events, `handle${string}`>;
// 'handleClick' | 'handleSubmit'type ApiResponse =
| { status: 'success'; data: any }
| { status: 'error'; error: string }
| { status: 'loading' }
| { status: 'idle' };
// Extract responses with data/error
type ResponseWithPayload = Extract<ApiResponse, { data: any } | { error: any }>;
// { status: 'success'; data: any } | { status: 'error'; error: string }
// Exclude loading states
type CompletedResponse = Exclude<ApiResponse, { status: 'loading' | 'idle' }>;
// { status: 'success'; data: any } | { status: 'error'; error: string }type EventMap = {
click: MouseEvent;
keydown: KeyboardEvent;
scroll: Event;
custom: CustomEvent;
};
type EventName = keyof EventMap;
// Extract only standard DOM events
type StandardEvents = Extract<EventName, 'click' | 'keydown' | 'scroll'>;
// 'click' | 'keydown' | 'scroll'
// Exclude standard events (get custom ones)
type CustomEvents = Exclude<EventName, 'click' | 'keydown' | 'scroll'>;
// 'custom'Built-in utility using Exclude:
type NonNullable<T> = Exclude<T, null | undefined>;
type MaybeString = string | null | undefined;
type DefiniteString = NonNullable<MaybeString>;
// stringtype User = {
id: string;
name: string;
age: number;
isActive: boolean;
email: string;
};
// Get keys with string values
type StringKeys<T> = {
[K in keyof T]: T[K] extends string ? K : never;
}[keyof T];
type UserStringKeys = StringKeys<User>;
// 'id' | 'name' | 'email'
// Extract string properties
type StringProps = Pick<User, Extract<keyof User, StringKeys<User>>>;interface Component {
_id: string;
_internal: boolean;
name: string;
value: string;
}
type PublicKeys<T> = Exclude<keyof T, `_${string}`>;
type PublicComponent = Pick<Component, PublicKeys<Component>>;
// {
// name: string;
// value: string;
// }type Shape =
| { kind: 'circle'; radius: number }
| { kind: 'square'; size: number }
| { kind: 'rectangle'; width: number; height: number };
type RoundShapes = Extract<Shape, { kind: 'circle' }>;
// { kind: 'circle'; radius: number }
type NonCircleShapes = Exclude<Shape, { kind: 'circle' }>;
// { kind: 'square'; size: number } | { kind: 'rectangle'; width: number; height: number }type ApiStatus = 'idle' | 'loading' | 'success' | 'error';
type ActiveStatus = Exclude<ApiStatus, 'idle'>;
// 'loading' | 'success' | 'error'
type CompletedStatus = Extract<ApiStatus, 'success' | 'error'>;
// 'success' | 'error'type Permission = 'read' | 'write' | 'delete' | 'admin';
type BasicPermissions = Exclude<Permission, 'admin'>;
// 'read' | 'write' | 'delete'
type ModifyPermissions = Extract<Permission, 'write' | 'delete'>;
// 'write' | 'delete'neverInstall with Tessl CLI
npx tessl i pantheon-ai/typescript-advancedreferences