UPDATE:
I have created an issue regarding this topic on github: https://github.com/Microsoft/TypeScript/issues/21265
It appears that the syntax{ ...other: xother }
is not valid in JavaScript or TypeScript, and should not compile.
Initial Query:
Consider the following scenario:
const values = { a: "1", b: "2", c: "3", d: "4" };
const { a: va, b: vb, ...other } = values;
where a new variable name va
is assigned to property a
.
According to TypeScript specifications, is it permissible to do the same with the remaining properties using ...other
? Like so:
const { a: va, b: vb, ...other: vother } = values;
It has been verified to work (online test). However, I am unable to locate where this behavior is officially specified.
The examples provided in the documentation typically demonstrate property renaming in a more standard manner: TypeScript Handbook - Variable Declarations. The specification grammar references a BindingPattern
which may not be clearly defined in the spec: TypeScript Spec.
My initial assumption is that this syntax might not be very practical since ...other
already serves as a custom variable name. Nonetheless, it functions as expected. I am intrigued to understand the specific definition behind it or if it is merely a working exception (which I doubt).