Frontend Engineering
Advanced TypeScript
Quiz: Type or Error? (Advanced)
advanced9 min read
Advanced Type System Challenges
Ready to go deep? These questions test the kind of type system knowledge that separates mid-level from staff-level engineers — conditional type distribution, variance rules, recursive types, template literal inference, and type-level computation. Each question requires you to trace the compiler's behavior step by step.
Scoring above 7 means you can confidently design complex type utilities. Getting all 10? That puts you in genuinely rare territory.
Question 1: Distributive Conditional Types
type IsString<T> = T extends string ? true : false;
type Result = IsString<string | number>;
Quiz
Question 2: Non-Distributive Trick
type IsString<T> = [T] extends [string] ? true : false;
type Result = IsString<string | number>;
Quiz
Question 3: infer in Covariant vs Contravariant Position
type Covariant<T> = T extends { a: infer U; b: infer U } ? U : never;
type Contravariant<T> = T extends { a: (x: infer U) => void; b: (x: infer U) => void } ? U : never;
type R1 = Covariant<{ a: string; b: number }>;
type R2 = Contravariant<{ a: (x: string) => void; b: (x: number) => void }>;
Quiz
Question 4: Template Literal Inference
type ParseRoute<T> =
T extends `${infer Method} /${infer Path}`
? { method: Method; path: Path }
: never;
type R = ParseRoute<"GET /users/123">;
Quiz
Question 5: Recursive Type Unwrapping
type Awaited<T> = T extends Promise<infer U> ? Awaited<U> : T;
type R = Awaited<Promise<Promise<Promise<number>>>>;
Quiz
Question 6: satisfies vs Annotation
const config = {
port: 3000,
host: "localhost",
} satisfies Record<string, string | number>;
type Port = typeof config.port;
Quiz
Question 7: Mapped Type Key Remapping
type FilterByValue<T, V> = {
[K in keyof T as T[K] extends V ? K : never]: T[K];
};
type Obj = { name: string; age: number; active: boolean; score: number };
type R = FilterByValue<Obj, number>;
Quiz
Question 8: Variance and Function Assignment
interface Animal { name: string }
interface Dog extends Animal { breed: string }
type AnimalCallback = (animal: Animal) => void;
type DogCallback = (dog: Dog) => void;
declare const dogCallback: DogCallback;
const animalCallback: AnimalCallback = dogCallback;
Quiz
Question 9: keyof Union vs keyof Intersection
type A = { x: number; y: string };
type B = { y: number; z: boolean };
type UnionKeys = keyof (A | B);
type IntersectionKeys = keyof (A & B);
Quiz
Question 10: Branded Types and Structural Typing
type USD = number & { readonly __brand: unique symbol };
type EUR = number & { readonly __brand: unique symbol };
declare function convert(amount: USD): EUR;
const dollars = 100 as USD;
const euros = 50 as EUR;
convert(dollars);
convert(euros);
Quiz
Scoring Guide
| Score | Assessment |
|---|---|
| 10/10 | Staff-engineer-level type system mastery. You can design and debug any type utility. |
| 8-9 | Advanced understanding. The edge cases you missed are worth studying. |
| 6-7 | Solid intermediate knowledge. Revisit variance, distribution, and recursive types. |
| 0-5 | Review the advanced TypeScript topics. Focus on infer, conditional distribution, and variance. |