microsoft / TypeScript

TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
https://www.typescriptlang.org
Apache License 2.0
99.5k stars 12.33k forks source link

Ghost errors and inconsistencies in destructuring patterns #59177

Closed ahejlsberg closed 2 weeks ago

ahejlsberg commented 3 weeks ago

🔎 Search Terms

Destructuring

🕗 Version & Regression Information

This changed in #56753

⏯ Playground Link

https://www.typescriptlang.org/play/?ssl=7&ssc=1&pln=1&pc=1#code/GYVwdgxgLglg9mABMOcAUBKRBvRAnAUyhDyQENEBfAKGogQGcpEBtMgGkQCNEBeRCgGpEARgC6fVgBYATGIDciRAHpliAKJ48cPIgAmMBmQAOxgmTwNEAdwAWBJCjiJDiegFt3DqAT2I4IFC09GBMrAAeIpwAniKSkRL8LCIyAMwKSqqIAHLOBFo6dIzMLOEyMTLx5YgAXpX80XKSyWkZKmoAqmAE4WbQvoj52rr2hNRAA

💻 Code

function foo() { return a }

const [a, b = a + 1] = [42];  // Error disappears when foo is commented out

const [x1, y1 = x1] = [123];  // No error
const [x2, y2 = x2, z2 = y2] = [123];  // Unexpected error here

🙁 Actual behavior

Unexpected errors.

🙂 Expected behavior

No errors.

Additional information about the issue

No response

ahejlsberg commented 3 weeks ago

TS 5.4 included #56753 as a fix for #49989. Unfortunately, the fix doesn't cover all cases and isn't the right way to solve the problem. In particular, seemingly unrelated changes to code samples cause errors to appear as illustrated by the repro.

I'm going to put up a PR that reverts #56753 and properly fixes #49989.