interface User extends Function {
player: number,
units: number[],
sites: string[],
}
class User extends Function {
constructor() {
super('return this.player')
[this.player, this.units, this.sites] = getBelongings(); // Destructuring Assignment
}
}
const me = new User();
function getBelongings(): [number, number[], string[]] {
return [1, [1], ['1']]
}
The above seems nice, and I think my assignment has no problem.
But It says: Type 'string[]' cannot be used as an index type.(2538)
I tried destructuring some times before and now have no idea about what's wrong.
Is it a TypeScript problem or a wrong syntax? And how can I make it operate well? Thanks a lot.
Functionand callingsuper("return this.player"). I very much doubt this will behave the way you intend at runtime, and TypeScript certainly has no idea what kind of function your instances ofUserwill be. Very little of that has to do with destructuring assignment; maybe you could edit the question to make it a plain example of your issue, like this.