Problem Statement
Explain NonNullable, Exclude, Extract, and give 1-line uses.
Explanation
NonNullable<T>: remove null and undefined. Use when you know a value is definitely present. Exclude<T, U>: take T and remove anything assignable to U. Use to filter unions. Extract<T, U>: take T and keep only members assignable to U. Use to intersect unions. Quick mental model: Exclude is “T minus U”; Extract is “T intersect U”; NonNullable is “T without nullish”.
Code Solution
SolutionRead Only
type A = string | number | null; type A1 = NonNullable<A>; // string | number type B = 'a' | 'b' | 'c'; type B1 = Exclude<B, 'b'>; // 'a' | 'c' type C = 'id' | 42 | true; type C1 = Extract<C, number>; // 42