-
Notifications
You must be signed in to change notification settings - Fork 12.9k
Closed
Labels
DuplicateAn existing issue was already createdAn existing issue was already created
Description
TypeScript Version: 3.7.2
Search Terms: generic inference optional chaining
Code
interface Base {
doBaseStuff(): void
}
interface Derived extends Base {
doDerivedStuff(): void
}
function a<T extends Base>(arg: T | undefined): T {
if (arg === undefined) {
throw new Error('It was undefined')
}
return arg
}
function f(arg?: { foo: Derived }): Derived {
return a(arg?.foo)
// Note that the following is completely okay:
// return a(arg?.foo as Derived | undefined)
}
Expected behavior: T
is inferred to be Derived
and type checking passes
Actual behavior: T
is inferred to be Base
and type checking fails
Related Issues:
jcalz
Metadata
Metadata
Assignees
Labels
DuplicateAn existing issue was already createdAn existing issue was already created