Consider the following TypeScript code using Exclude. What is the type of Result?
type Letters = 'a' | 'b' | 'c' | 'd'; type Result = Exclude<Letters, 'a' | 'd'>; // What is the type of Result?
The Exclude type removes the types on the right from the union on the left.
The Exclude utility type removes 'a' and 'd' from the union 'a' | 'b' | 'c' | 'd', leaving 'b' | 'c'.
Given this code, what is the type of Filtered?
type Status = 'success' | 'error' | 'loading'; type Filtered = Exclude<Status, 'loading'>;
Exclude removes the specified type from the union.
Removing 'loading' from Status leaves 'success' | 'error'.
What is the resulting type of KeysWithoutId?
type Obj = { id: number; name: string; age: number };
type Keys = keyof Obj;
type KeysWithoutId = Exclude<Keys, 'id'>;Use keyof to get keys, then exclude 'id'.
keyof Obj is 'id' | 'name' | 'age'. Excluding 'id' leaves 'name' | 'age'.
What error will this code produce?
type A = 'x' | 'y'; type B = Exclude<A, 'z'>; const test: B = 'z';
Check if the assigned value is part of the type after exclusion.
Since 'z' is not in 'x' | 'y', assigning 'z' to test causes a type error.
Given this code, how many string literal types remain in Remaining?
type All = 'red' | 'green' | 'blue' | 'yellow' | 'black'; type Remove = 'green' | 'yellow' | 'white'; type Remaining = Exclude<All, Remove>;
Count how many items from All are not in Remove.
Remove includes 'green' and 'yellow' which are removed from All. The remaining are 'red', 'blue', and 'black', so 3 items.