You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
This is not related to optional chaining. Unions have never allowed access to non-common members of union constituent:
constx=(o: {a: number}|{b: string})=>{o.a// error if(o.a){// error even though could conceivable be a type guard}if('a'ino){// ok type guardo.a// o is now narrowed to { a: number }}}
TypeScript Version: 3.7.2
Search Terms:
Expected behavior:
Typescript should handle the optional method as same as optional properties
Actual behavior:
Typescript throws a warning:
The code itself is doing what I expected. When the method is not found, it uses the right hand value.
Related Issues:
No issue found
Code
Output
Compiler Options
Playground Link: Provided
The text was updated successfully, but these errors were encountered: