Closed
Description
TypeScript Version: 3.7.2
Search Terms:
optional chaining
optional chaining union
Code
interface Common {
name: string
age: number
}
interface A extends Common{
address: string
}
interface B extends Common{
city: string
}
type MyType = A | B
const func = (arg?: MyType) => {
const res = arg?.city // city does not exist on type A
}
Expected behavior:
Optional chaining works well in this situation as arg
might be of B
type.
Actual behavior:
Fails with TS error city does not exist on type A
.
Related Issues: no