Partial TransformationProblem Statement'Write a function update(obj: User, fields: Partial<User>) where User has name and age.'Approach 1. `Partial<T>` makes all properties of `T` optional. Solution`interface User { name: string; age: number;
Pick PropertiesProblem Statement'Create a type UserPreview by picking name from User interface.'Approach 1. Use `Pick<T, K>` where `K` is a set of keys. Solution`interface User { id: number; name: string; email: string;
Omit PropertiesProblem Statement'Create a type UserWithoutId by omitting "id" from the User interface.'Approach 1. Use `Omit<T, K>` to exclude keys. Solution`interface User { id: number; username: string;
Readonly UtilityProblem Statement'Define a type ReadonlyUser that makes all properties of User immutable.'Approach 1. Use `Readonly<T>`. Solution`interface User { name: string;
Record TypeProblem Statement'Define a type PageInfo that is a map of string keys to objects containing a title(string).'Approach 1. Use `Record<Keys, Type>`. Solution`type PageInfo = Record<string, { title: string
Required PropertiesProblem Statement'Given an interface with optional props, create a type where all props are mandatory.'Approach 1. Use `Required<T>`. Solution`interface Props { a?: string; b?: number;
Exclude from UnionProblem Statement'From a union type "a" | "b" | "c", exclude "c".'Approach 1. Use `Exclude<UnionType, ExcludedMembers>`. Solutiontype Letters = "a" | "b" | "c"; type SmallLetters = Exclude<Letters, "c">; // "a" | "b" string
Extract from UnionProblem Statement'From a union string | number | boolean, extract only string | number.'Approach 1. Use `Extract<Type, Union>`. Solutiontype MyTypes = string | number | boolean; type Primitive = Extract<MyTypes, string | number>;
NonNullable TypeProblem Statement'Create a type that filters out null and undefined from string | null | undefined.'Approach 1. Use `NonNullable<T>`. Solutiontype MayBeString = string | null | undefined; type SureString = NonNullable<MayBeString>;
Function ParametersProblem Statement'Given a function type, extract its parameters as a tuple.'Approach 1. Use `Parameters<T>`. Solutiontype GreetFn = (name: string, age: number) => void; type GreetArgs = Parameters<GreetFn>; // [string, number]
Return TypeProblem Statement'Extract the return type of a function that returns a Promise<string>.'Approach 1. Use `ReturnType<T>`. Solutiontype FetchFn = () => Promise<string>; type FetchedData = ReturnType<FetchFn>; // Promise<string>
Awaited TypeProblem Statement'Unwrap a Promise type to get the actual value type.'Approach 1. Use `Awaited<T>`. Solutiontype PromiseString = Promise<string>; type JustString = Awaited<PromiseString>; // string
Pick MultipleProblem Statement'Pick "id" and "email" from a User interface.'Approach 1. Use the pipe `|` in the second argument of `Pick`. Solution`interface User { id: number; name: string; email: string;
Record with EnumProblem Statement'Create a Record where keys are an enum TaskStatus and values are strings.'Approach 1. Enums work as keys in Records. Solution`enum TaskStatus { Todo, Done
Instance TypeProblem Statement'Extract the instance type from a class constructor.'Approach 1. Use `InstanceType<T>`. Solution`class Point { x = 0; y = 0;
Level 1 PartialProblem Statement'Does Partial work recursively on nested objects?'Approach 1. No, `Partial` is shallow. Solution`interface Nested { a: { b: string
Readonly ArrayProblem Statement'Define an array that cannot be modified.'Approach 1. Use `ReadonlyArray<T>` or `readonly T[]`. Solutionconst nums: ReadonlyArray<number> = [1, 2, 3]; // nums.push(4); // Error
Omit MultipleProblem Statement'Omit "password" and "salt" from a UserAccount interface.'Approach 1. Use pipe in the second argument of `Omit`. Solution`interface UserAccount { user: string; password: string; salt: string;
Strict Key RecordProblem Statement'Create a record that MUST contain keys "A", "B", and "C".'Approach 1. Use a string literal union as the key type. Solution`type Triplet = Record<"A" | "B" | "C", number>; const t: Triplet = { A: 1, B: 2, C: 3
This ParameterProblem Statement'Extract the type of "this" used in a function.'Approach 1. Use `ThisParameterType<T>`. Solution`function toHex(this: Number) { return this.toString(16);