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

Under `strictFunctionTypes`, why is the first assignment accepted while the second is rejected, given the parameter types are identical?

interface WithMethod { handle(e: Animal): void } interface WithProp { handle: (e: Animal) => void } type Animal = { name: string }; type Dog = Animal & { bark(): void }; declare let m: WithMethod; declare let mDog: { handle(e: Dog): void }; declare let p: WithProp; declare let pDog: { handle: (e: Dog) => void }; m = mDog; // (1) p = pDog; // (2)