skills/typescript-advanced-types/SKILL.md
Master TypeScript's advanced type system including generics, conditional types, mapped types, template literals, and utility types for building type-safe applications. Use when implementing complex type logic, creating reusable type utilities, or ensuring compile-time type safety in TypeScript projects.
npx skillsauth add Chris-Maskey/opencode-config typescript-advanced-typesInstall this skill globally with one command. Works with Claude Code, Cursor, and Windsurf.
3 of 9 scanners reported clean
Some scanners were skipped, did not run, or reported a non-clean status. Review each row below.
Comprehensive guidance for mastering TypeScript's advanced type system including generics, conditional types, mapped types, template literal types, and utility types for building robust, type-safe applications.
Create reusable, type-flexible components while maintaining type safety.
function identity<T>(value: T): T {
return value;
}
const num = identity<number>(42); // Type: number
const str = identity<string>("hello"); // Type: string
const auto = identity(true); // Type inferred: boolean
Create types that depend on conditions.
type IsString<T> = T extends string ? true : false;
type A = IsString<string>; // true
type B = IsString<number>; // false
Transform existing types by iterating over their properties.
type Readonly<T> = {
readonly [P in keyof T]: T[P];
};
type Partial<T> = {
[P in keyof T]?: T[P];
};
Create string-based types with pattern matching.
type EventName = "click" | "focus" | "blur";
type EventHandler = `on${Capitalize<EventName>}`;
// Type: "onClick" | "onFocus" | "onBlur"
Built-in utility types for common transformations:
Partial<T> // Make all properties optional
Required<T> // Make all properties required
Readonly<T> // Make all properties readonly
Pick<T, K> // Select specific properties
Omit<T, K> // Remove specific properties
If a type parameter appears only in the function signature, it's likely unnecessary.
// Bad - T only appears in signature, not in return or body
function getRelationName<T extends 'department' | 'location'>(
data: Career['data'],
field: T
): string | null {
return data?.[field]?.name ?? null
}
// Good - no unnecessary generic, use union directly
function getRelationName(
data: Career['data'],
field: 'department' | 'location' | 'employmentType'
): string | null {
return data?.[field]?.name ?? null
}
This skill provides detailed examples through context files. Load them when needed:
| Context File | When to Load |
| --------------------------------- | ----------------------------------------------- |
| context/core-examples.md | Need generics, conditionals, mapped types examples |
| context/patterns.md | Implementing real-world patterns (EventEmitter, API client, Builder) |
| context/techniques.md | Type inference, guards, assertions, testing |
type ElementType<T> = T extends (infer U)[] ? U : never;
type PromiseType<T> = T extends Promise<infer U> ? U : never;
type Parameters<T> = T extends (...args: infer P) => any ? P : never;
function isString(value: unknown): value is string {
return typeof value === "string";
}
function isArrayOf<T>(
value: unknown,
guard: (item: unknown) => item is T
): value is T[] {
return Array.isArray(value) && value.every(guard);
}
function assertIsString(value: unknown): asserts value is string {
if (typeof value !== "string") {
throw new Error("Not a string");
}
}
// Problem: Omit doesn't validate key exists
type UserWithoutPassword = Omit<User, 'passwrod'>; // No error for typo
// Solution: StrictOmit validates the key exists
type StrictOmit<T, K extends keyof T> = Omit<T, K>;
type SafeUser = StrictOmit<User, 'passwrod'>; // TypeScript error!
type UniformResourceLocator = string & { _brand: 'url' };
const isURL = (candidate: unknown): candidate is UniformResourceLocator => {
return z.url().safeParse(candidate).success;
};
function fetchFromAPI(url: UniformResourceLocator) { /* ... */ }
const url = 'https://example.com';
// fetchFromAPI(url); // Error! Not branded
if (isURL(url)) {
fetchFromAPI(url); // OK - type guard validated
}
unknown over any: Enforce type checkinginterface for object shapes: Better error messagestype for unions and complex types: More flexibleany: Defeats the purpose of TypeScript// Avoid duplication
const userSchema = z.object({
id: z.string(),
name: z.string(),
email: z.string().email(),
});
type User = z.infer<typeof userSchema>;
tools
Anti-patterns and mistakes to avoid as a product manager. Use when evaluating leadership behaviors, improving team dynamics, reflecting on management practices, or onboarding new product managers.
development
Review UI code for Web Interface Guidelines compliance. Use when asked to "review my UI", "check accessibility", "audit design", "review UX", or "check my site against best practices".
testing
Design effective CTAs using visual attention and gaze psychology principles. Use when designing landing pages, button hierarchies, conversion elements, or optimizing user attention flow through interfaces.
tools
Run agent-browser + Chrome inside Vercel Sandbox microVMs for browser automation from any Vercel-deployed app. Use when the user needs browser automation in a Vercel app (Next.js, SvelteKit, Nuxt, Remix, Astro, etc.), wants to run headless Chrome without binary size limits, needs persistent browser sessions across commands, or wants ephemeral isolated browser environments. Triggers include "Vercel Sandbox browser", "microVM Chrome", "agent-browser in sandbox", "browser automation on Vercel", or any task requiring Chrome in a Vercel Sandbox.