Demo
TypeScript source with nightly version 3.8.0-dev.20191224
typeAddress={city: string}typeUser={home: Address|undefinedwork: Address|void}declareletu: Useru.home?.cityu.work?.cityJavaScript output the same for both "work" and "home" properties
"use strict";var_a,_b;(_a=u.work)===null||_a===void0 ? void0 : _a.city;(_b=u.home)===null||_b===void0 ? void0 : _b.city;
Bug
If you run the code above, you will see that for u.home?.city there are no errors.
But for u.work?.city there is an error:
Error: Property 'city' does not exist on type 'void | Address'
Expectation
Optional chaining works for both 'undefined' and 'void' types the same way.
Demo
playground demo
TypeScript source with nightly version 3.8.0-dev.20191224
JavaScript output
the same for both "work" and "home" propertiesBug
If you run the code above, you will see that for
u.home?.citythere are no errors.But for
u.work?.citythere is an error:Error: Property 'city' does not exist on type 'void | Address'Expectation
Optional chaining works for both 'undefined' and 'void' types the same way.