tracked-tools / tracked-built-ins

Tracked versions of JavaScript's built-in classes

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

TrackedArray type too wide?

NullVoxPopuli opened this issue · comments

currently, this fails with a type error:

type XIndex = 0 | 1;
type YIndex = 0 | 1 | 2;
let arr: [XIndex, YIndex] = new TrackedArray([0, 0]])

TrrackedArray infers generic <number>, but that's kinda incorrect here.
I can cast with as, but obvs inference is always nice when it works, so I wan wondering if there was a way to change the definition of TrackedArray so that inference could work in this situation.

TS infers TrackedArray<number> because that's what Array would infer there—and in fact, that's what's happening: what you pass to it is an Array<number>. Arrays aren't typed as tuples unless you do so explicitly, including even with const.