Skip to content

CFA with optional chaining #33806

Closed
@falsandtru

Description

@falsandtru

@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:

Metadata

Metadata

Assignees

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