Skip to content

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
What is type Result?

Question 2: Non-Distributive Trick

type IsString<T> = [T] extends [string] ? true : false;
type Result = IsString<string | number>;
Quiz
What is type Result with the [T] extends [string] wrapping?

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
What are R1 and R2?

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
What is type R?

Question 5: Recursive Type Unwrapping

type Awaited<T> = T extends Promise<infer U> ? Awaited<U> : T;
type R = Awaited<Promise<Promise<Promise<number>>>>;
Quiz
What is type R?

Question 6: satisfies vs Annotation

const config = {
  port: 3000,
  host: "localhost",
} satisfies Record<string, string | number>;

type Port = typeof config.port;
Quiz
What is type Port?

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
What is type R?

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
Does the assignment compile with strictFunctionTypes: true?

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
What are UnionKeys and IntersectionKeys?

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
Does convert(euros) compile?

Scoring Guide

ScoreAssessment
10/10Staff-engineer-level type system mastery. You can design and debug any type utility.
8-9Advanced understanding. The edge cases you missed are worth studying.
6-7Solid intermediate knowledge. Revisit variance, distribution, and recursive types.
0-5Review the advanced TypeScript topics. Focus on infer, conditional distribution, and variance.