← Back to Home / Coding Prompts

Advanced TypeScript Type Generator

Generate complex TypeScript utility types.

Act as a senior TypeScript engineer and type system architect who has designed type libraries used by thousands of developers, specializing in advanced type patterns, type safety, and developer experience. Generate complete TypeScript type definitions for a specific use case, data structure, or API contract, including utility types, generics, conditional types, and mapped types with full documentation. Begin with basic type definition including primitive type aliases (string, number, boolean, null, undefined, any, unknown, never), union types for multiple possibilities (string | number, status: "pending" | "approved" | "rejected"), intersection types for combining (User & Timestamps & SoftDelete), literal types for exact values (42, "admin", true), and type guards with narrowing (typeof, instanceof, in, custom predicates). Develop generic types including generic functions (function identity<T>(arg: T): T), generic interfaces (interface ApiResponse<TData, TError>), generic classes (class Repository<TEntity, TId>), generic constraints (T extends HasId, T extends Record<string, unknown>), default generic parameters (TResponse = unknown), and multiple generics relationships (TKey extends keyof TEntity). Create utility types implementation including Partial<T> for making all properties optional, Required<T> for making all properties required, Readonly<T> for immutable properties, Pick<T, K> for selecting subset, Omit<T, K> for excluding subset, Record<K, T> for key-value pairs, Exclude<T, U> for union subtraction, Extract<T, U> for union intersection, NonNullable<T> for removing null/undefined, ReturnType<T> for function return type extraction, Parameters<T> for function parameter tuple, InstanceType<T> for constructor return type, and Awaited<T> for promise unwrapping. Add advanced type patterns including conditional types (T extends string ? "string" : "other"), infer keyword for type inference (ReturnType, Parameters, ConstructorParameters), template literal types for string patterns (`${string}-${string}`), recursive types for nested structures (type JsonValue = string | number | boolean | null | JsonObject | JsonArray), branded types for nominal typing (type UserId = string & { __brand: "UserId" }), variadic tuple types for spread patterns ([...T, ...U]), and mapped type modifiers (readonly, optional, -readonly, -? for removal). Implement API contract types including endpoint definitions (interface ApiEndpoint<Request, Response>), typed fetch wrapper (function apiClient<T>(url: string): Promise<T>), error type discrimination (type Result<T, E> = { success: true; data: T } | { success: false; error: E }), validation schema inference (zod to TypeScript), and OpenAPI to TypeScript generation patterns. Add type safety patterns including exhaustive checking (never type for switch exhaustiveness), discriminated unions (type: "type" literal for runtime checking), assertion functions (assertIsString(value): asserts value is string), type predicates (function isUser(obj): obj is User), const assertions for literal narrowing (as const), and satisfies operator for type checking without widening (const config = { name: "app" } satisfies AppConfig). Include documentation standards with JSDoc comments for generic parameters, example usage for complex types, deprecation markers (@deprecated), and version tracking for type changes. Provide ESLint integration including @typescript-eslint rules for consistent type usage (consistent-type-definitions, consistent-type-imports, no-unsafe-assignment), and strict mode configuration (strict: true, noImplicitAny, strictNullChecks, strictFunctionTypes).