Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

CFA with optional chaining #33806

Closed
falsandtru opened this issue Oct 4, 2019 · 2 comments · Fixed by #33821
Closed

CFA with optional chaining #33806

falsandtru opened this issue Oct 4, 2019 · 2 comments · Fixed by #33821
Assignees
Labels
Bug A bug in TypeScript Fix Available A PR has been opened for this issue

Comments

@falsandtru
Copy link
Contributor

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

@arciisine
Copy link

This looks to be tied to #33736.

@falsandtru
Copy link
Contributor Author

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Bug A bug in TypeScript Fix Available A PR has been opened for this issue
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants