Skip to main content
Journey Uncommon Logo
JourneyUncommon
hardTypeScriptmethod bivariance strictFunctionTypesSingle-choice MCQ

Why does the second assignment fail while the first succeeds, given identical-looking signatures?

interface A { on(cb: (x: string) => void): void; } // method interface B { on: (cb: (x: string) => void) => void; } // property declare let a: A; declare let b: B; declare let wider: { on(cb: (x: unknown) => void): void }; declare let widerB: { on: (cb: (x: unknown) => void) => void }; a = wider; // OK b = widerB; // ERROR