It seems there is a discrepancy in how interfaces are checked when they are declared with properties versus methods. Specifically, assuming some object whose shape doesn't really matter:
interface ObjectInQuestion {
value: any
}
these interfaces:
interface FirstInterface {
callback(obj: Partial<ObjectInQuestion>): void;
}
interface SecondInterface {
callback: (obj: Partial<ObjectInQuestion>) => void;
}
typecheck differently:
function takesFirstInterfacePasses(_: FirstInterface) { }
function takesSecondInterfaceFails(_: SecondInterface) { }
function thisTakesEntireObject(_: ObjectInQuestion) { }
function whyDoTheseFunctionsCheckDifferently() {
takesFirstInterfacePasses({ callback: thisTakesEntireObject })
takesSecondInterfaceFails({ callback: thisTakesEntireObject })
}
Could someone help me understand why this is?
Here's a link to a repro in the TS Playground