You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Search Terms: namespace rest export number numeric object destructuring pattern
Code
namespaceFoo{exportlet{0: a, ...b}=[0,1]console.log(JSON.stringify({a, b}))}
Expected behavior:
I expect this to log {"a":0,"b":{"1":1}} because that's what you get when you run the following JavaScript natively:
let{0: a, ...b}=[0,1];console.log(JSON.stringify({a, b}))
Actual behavior:
This actually logs {"a":0,"b":{"0":0,"1":1}}.
I'm working on my own TypeScript parser for esbuild, a JavaScript bundler, and I noticed that the code TypeScript generates for destructuring object properties has this bug. The generated code for the sample above looks like this:
The problem is that the numeric property is passed to __rest as a number, not as a string, but __rest is implemented using indexOf which doesn't consider 0 and "0" to be equal.
I think the most straightforward fix would be for the compiler to emit __rest(_a, ["0"]) instead of __rest(_a, [0]).
TypeScript Version: Nightly
Search Terms: namespace rest export number numeric object destructuring pattern
Code
Expected behavior:
I expect this to log
{"a":0,"b":{"1":1}}
because that's what you get when you run the following JavaScript natively:Actual behavior:
This actually logs
{"a":0,"b":{"0":0,"1":1}}
.I'm working on my own TypeScript parser for esbuild, a JavaScript bundler, and I noticed that the code TypeScript generates for destructuring object properties has this bug. The generated code for the sample above looks like this:
The problem is that the numeric property is passed to
__rest
as a number, not as a string, but__rest
is implemented usingindexOf
which doesn't consider0
and"0"
to be equal.I think the most straightforward fix would be for the compiler to emit
__rest(_a, ["0"])
instead of__rest(_a, [0])
.Playground Link: https://www.typescriptlang.org/play/?ts=Nightly#code/HYQwtgpgzgDiDGEAEAxA9mpBvJAoJBSEAHjGgE4AuSANhNTgAwBcSIANEgHQ8BGSAXyQBeJAG1GnAIwBdfIXhpgUNHS400AcwAUAKQDKAeQByXKJXIBLYJssAzAJ7asHJLwEBKD7gG4gA
Related Issues: I couldn't find any existing issues about this.
The text was updated successfully, but these errors were encountered: