TypeScript Version: 2.2.1
Code
interface A {
b?(): void
}
function works<T extends A>(a: T) {
if (a.b) a.b()
}
function worksToo(a: Readonly<A>) {
if (a.b) a.b()
}
function doesntWork<T extends A>(a: Readonly<T>) {
if (a.b) a.b()
// Cannot invoke an expression whose type lacks a call signature.
// Type '(() => void) | undefined' has no compatible call signatures.
}
Note that there is no Object is possibly 'undefined' message here.
Expected behavior:
After if check method should be considered defined.
Actual behavior:
Member type is not inferred correctly.
TypeScript Version: 2.2.1
Code
Note that there is no
Object is possibly 'undefined'message here.Expected behavior:
After
ifcheck method should be considered defined.Actual behavior:
Member type is not inferred correctly.