Custom ReadonlyProblem Statement'Implement a mapped type MyReadonly<T> that behaves like the built-in Readonly<T>.'Approach` 1. Use the syntax `{ readonly [P in keyof T]: T[P]Solution`type MyReadonly<T> = { readonly [P in keyof T]: T[P];
Custom PartialProblem Statement'Implement a mapped type MyPartial<T> using the "-?" or "?" operator.'Approach 1. Use `[P in keyof T]?:`. Solution`type MyPartial<T> = { [P in keyof T]?: T[P];
IsString ConditionalProblem Statement'Write a conditional type IsString<T> that returns true if T is string, else false.'Approach 1. Use `T extends string ? true : false`. Solutiontype IsString<T> = T extends string ? true : false;
Infer Return TypeProblem Statement'Use "infer" to extract the first element type of an array.'Approach 1. Use `T extends [infer F, ...any] ? F : never`. Solutiontype First<T extends any[]> = T extends [infer F, ...any] ? F : never;
Template Literal TypeProblem Statement'Create a type ColorCode that combines "red" | "blue" with "light" | "dark" using template literals.'Approach` 1. Use backticks inside type definition: `${ASolution`type Intensity = "light" | "dark"; type Color = "red" | "blue"; type ColorCode = `${Intensity
Key RemappingProblem Statement'Create a type Getters<T> that turns every property "x" into "getX".'Approach` 1. Use `as` in mapped types: `[P in keyof T as `get${Capitalize<string & P>Solution`type Getters<T> = { [P in keyof T as `get${Capitalize<string & P>
Implement ExcludeProblem Statement'Implement the Exclude<T, U> utility type using conditional types.'Approach 1. If `T` extends `U`, return `never`, else return `T`. Solutiontype MyExclude<T, U> = T extends U ? never : T;
Implement ParametersProblem Statement'Implement the Parameters<T> utility using "infer".'Approach 1. `T` must extend `(...args: any) => any`. 2. Infer the args. Solutiontype MyParameters<T extends (...args: any) => any> = T extends (...args: infer P) => any ? P : never;
Implement PickProblem Statement'Implement Pick<T, K> using mapped types.'Approach 1. `K` must extend `keyof T`. Solution`type MyPick<T, K extends keyof T> = { [P in K]: T[P];
Implement OmitProblem Statement'Implement Omit<T, K> by combining Pick and Exclude.'Approach 1. Pick the keys that are `Exclude<keyof T, K>`. Solutiontype MyOmit<T, K extends keyof any> = MyPick<T, MyExclude<keyof T, K>>;
Deep ReadonlyProblem Statement'Create a DeepReadonly<T> that works recursively.'Approach 1. Check if `T[P]` is an object. If yes, recurse. Solution`type DeepReadonly<T> = { readonly [P in keyof T]: T[P] extends object ? DeepReadonly<T[P]> : T[P];
Extract Required KeysProblem Statement'Create a type that extracts only the keys of T that are mandatory.'Approach` 1. Use `{Solution`type RequiredKeys<T> = { [K in keyof T]-?: {
Uncurried String TupleProblem Statement'Convert a union "A" | "B" into a tuple ["A", "B"] (Conceptual).'Approach 1. Note: This is extremely complex and involves function overloads/intersection hack. Solution// Conceptual - requires complex boilerplate usually found in Type-Fest // type UnionToTuple<T> = ...
ThisType UtilityProblem Statement'Explain the purpose of the ThisType<T> utility.'Approach 1. Used to control the type of `this` in an object literal. Solution`interface MyState { data: string
Distributive ConditionalsProblem Statement'What happens when you pass a union to Box<T> where Box<T> = T extends any ? T[] : never?'Approach 1. Conditionals distribute over unions: `(A | B)[]` becomes `A[] | B[]`. Solutiontype Box<T> = T extends any ? T[] : never; type Res = Box<string | number>; // string[] | number[]
Tuple to UnionProblem Statement'Convert [1, 2, 3] into 1 | 2 | 3.'Approach 1. Use indexing: `T[number]`. Solutiontype Tuple = [1, 2, 3]; type Union = Tuple[number]; // 1 | 2 | 3
Extract Readonly ValuesProblem Statement'Extract values of an object where the keys are string and values are number.'Approach 1. Use indexed access. Solution`type Map = { a: 1; b: 2; c: "3"
Implement AwaitedProblem Statement'Implement a basic MyAwaited<T>.'Approach 1. Recurse if `T` extends `Promise<infer U>`. Solutiontype MyAwaited<T> = T extends Promise<infer U> ? MyAwaited<U> : T;
Flatten TupleProblem Statement'Flatten [1, [2, 3], 4] into [1, 2, 3, 4].'Approach 1. Use variadic tuple types and recursion. Solutiontype Flatten<T extends any[]> = T extends [infer F, ...infer R] ? [...(F extends any[] ? Flatten<F> : [F]), ...Flatten<R>] : [];
Nominal Typing (Branding)Problem Statement'Implement "Branding" to create a UserId type that cannot be mixed with regular strings.'Approach` 1. Use intersection with a unique object: `string & { __brand: "UserId"Solution`type Brand<K, T> = K & { __brand: T