ezno icon indicating copy to clipboard operation
ezno copied to clipboard

Type of arrays and other collection types

Open kaleidawave opened this issue 1 year ago • 1 comments

Given an array like

let x = [1, 4, "item"]

It is typed (or will be as { [0]: 1, [1]: 4, [2]: "item" }). The problem is how to reference its prototype.

Array is a generic structure so it could be Array<1 | 4 | "item">. However it would have to be modified every push...

It is needed to test equality

let x: Array<number> = [1, 4, "item"]

Alternatively the T type could be figured out from items. Along the lines of interface Array<T is this[number]>...

This also affects Set, Map, which could be done like

interface Map<K is this.#items[number][0], V is this.#items[number][1]> {
    #items: Array<[K, V]>
}

and also Promise!!!

interface Promise<T is ReturnType<this.#func>> {
    #func: Function
}

kaleidawave avatar Jun 16 '23 12:06 kaleidawave