-
Notifications
You must be signed in to change notification settings - Fork 13.2k
Open
Labels
BugA bug in TypeScriptA bug in TypeScriptDomain: check: Control FlowThe issue relates to control flow analysisThe issue relates to control flow analysisHelp WantedYou can do thisYou can do this
Milestone
Description
🔎 Search Terms
destructuring, Cannot destructure as it is undefined, optional chaining destructuring
🕗 Version & Regression Information
- This changed between versions ______ and _______
- This changed in commit or PR _______
- This is the behavior in every version I tried, and I reviewed the FAQ for entries about _________
- I was unable to test this on prior versions because _______
⏯ Playground Link
💻 Code
const input: {
a?: { b?: { c: string } }
} = { a: undefined }
const { ...b } = input.a?.b🙁 Actual behavior
No error reported by TypeScript.
🙂 Expected behavior
TypeScript should have an indicative error, since this expression might result in undefined, which cannot be destructured.
Rest types may only be created from object types.(2700)
Additional information about the issue
The error in the JavaScript being ran is:
Uncaught TypeError: Cannot destructure '(intermediate value)' as it is undefined.
chernodub
Metadata
Metadata
Assignees
Labels
BugA bug in TypeScriptA bug in TypeScriptDomain: check: Control FlowThe issue relates to control flow analysisThe issue relates to control flow analysisHelp WantedYou can do thisYou can do this
