All quizzesHard
TypeScript Advanced — Series 3
Preview — 3 of 10 questions
javascript
type IsArray<T> = T extends unknown[] ? "yes" : "no";
type Wrapped<T> = [T] extends [unknown[]] ? "yes" : "no";
type A = IsArray<string[] | number>;
type B = Wrapped<string[] | number>;AA is "yes", B is "yes"
BA is "yes" | "no", B is "no"
CA is "no", B is "yes" | "no"
DBoth are "no" — a union never extends unknown[]
javascript
interface Source {
readonly id: string;
name?: string;
}
type Copy<T> = { [K in keyof T]: T[K] };
type Rebuilt = { [K in keyof Source]: Source[K] };
type R1 = Copy<Source>;AR1 is { id: string; name: string } — mapping always strips readonly and ?
BR1 is { readonly id: string; name: string } — readonly survives, ? does not
CR1 is { id: string; name?: string } — ? survives, readonly does not
DR1 is { readonly id: string; name?: string } — a homomorphic mapped type copies both modifiers
javascript
type Unwrap<T> = T extends Promise<infer U> ? U : T;
type A = Unwrap<Promise<string>>;
type B = Unwrap<Promise<Promise<number>>>;
type C = Unwrap<boolean>;AA is string, B is Promise<number>, C is boolean
BA is string, B is number, C is boolean
CA is string, B is number, C is never
DA is Promise<string>, B is Promise<Promise<number>>, C is boolean
Sign up free to play
Answer all 10 questions (7 more), see explanations for every answer, and track your score.