EDIT:
I opened an issue related to this on github: https://github.com/Microsoft/TypeScript/issues/21265
It seems that{ ...other: xother }
is not valid JS, neither TS, code and it should not even compile.
Original question:
Let's assume the following example:
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 for property a
.
Is it valid, according to TypeScript specs, to do the same with the remaining properties ...other
? Something like:
const { a: va, b: vb, ...other: vother } = values;
I know it works, I've tested it (online test). But I'm unable to find where it's defined to do so.
The examples of the documents that refers to property renaming always show the "normal" case: TypeScript Handbook - Variable Declarations. And the spec grammar refres to a BindingPattern
that's no described (or I've missed) in the spec: TypeScript Spec.
My first impression is that it is not very useful since ...other
is already a custom variable name. But it works. And I'm curious to know where it is specifically defined or if it's only a corner case that works (I suppose not).