Microsoft/TypeScript

Nested destructuring does not narrow dependent parameters

Open

#48.378 geöffnet am 22. März 2022

Auf GitHub ansehen
 (2 Kommentare) (0 Reaktionen) (0 zugewiesene Personen)TypeScript (6.726 Forks)batch import
BugDomain: check: Control FlowHelp Wanted

Repository-Metriken

Stars
 (48.455 Stars)
PR-Merge-Metriken
 (Durchschn. Merge 6T 17h) (9 gemergte PRs in 30 T)

Beschreibung

Bug Report

🔎 Search Terms

destructuring destructured dependent parameters nested control flow analysis

🕗 Version & Regression Information

  • This changed between versions 4.5.5 and 4.6

⏯ Playground Link

Playground link with relevant code

💻 Code

declare const Tuple: [true, string] | [false, number];
const [[val1, val2]] = [Tuple];
if (val1) {
	val2 // string | number
}

🙁 Actual behavior

TypeScript does not correctly narrow val2 when narrowing val1 if it's in any type of nested destructuring.

🙂 Expected behavior

I expect it to behave the same as directly destructuring the object.

Contributor Guide