Skip to main content
Journey Uncommon Logo
JourneyUncommon
hardTypeScriptstructural typing unsoundnessSingle-choice MCQ

Under `strictFunctionTypes`, function parameters are checked contravariantly, but there is a deliberate exception. Why does `h2 = narrow2` error while `h1 = narrow1` does not?

interface M { handle(x: string): void; } // method syntax type P = { handle: (x: string) => void }; // property syntax declare let h1: M; declare let h2: P; declare let narrow1: { handle(x: "a"): void }; declare let narrow2: { handle: (x: "a") => void }; h1 = narrow1; // ok h2 = narrow2; // error