Skip to content

Optional chaining not working with void type #35850

Description

Demo

playground 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?.city

JavaScript 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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    BugA bug in TypeScriptDomain: Something ElseFallback label when we just can't figure anything else out

    Type

    No type

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions