Skip to content

CFA with optional chaining #33806

Closed

Description

@falsandtru

Ron Buckton (@rbuckton)

TypeScript Version: master

Search Terms:

Code

declare const o: { x: 0 } | undefined;
if (o?.x === 0) {
  o.x;
}
declare const a: [0] | undefined;
if (a?.[0] === 0) {
  a[0];
}

Expected behavior:
pass
Actual behavior:

$ node built/local/tsc --noEmit --strict index.ts
index.ts:3:3 - error TS2532: Object is possibly 'undefined'.

3   o.x;
    ~

index.ts:7:3 - error TS2532: Object is possibly 'undefined'.

7   a[0];
    ~


Found 2 errors.

Playground Link:

Related Issues:

Activity

  1. arciisine commented on Oct 4, 2019

    @arciisine

    This looks to be tied to #33736.

  2. falsandtru commented on Oct 4, 2019

    @falsandtru
    ContributorAuthor

    The same idea is commented there but that issue doesn't aim it.

  3. locked as resolved and limited conversation to collaborators on Oct 21, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Labels

BugA bug in TypeScriptFix AvailableA PR has been opened for this issue

Type

No type

Projects

No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions