Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Lookup/computed generics for collection types & more #34

Open
kaleidawave opened this issue Jun 16, 2023 · 4 comments
Open

Lookup/computed generics for collection types & more #34

kaleidawave opened this issue Jun 16, 2023 · 4 comments
Assignees
Labels
blocking These issues are blocking the checker being used in projects checking Issues around checking subtyping Related to comparing two types
Milestone

Comments

@kaleidawave
Copy link
Owner

kaleidawave commented Jun 16, 2023

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!!! (see #168)

@kaleidawave kaleidawave added feedback-needed Extra attention/consensus is needed checking Issues around checking subtyping Related to comparing two types labels Jun 16, 2023
@kaleidawave kaleidawave self-assigned this Jun 23, 2023
@kaleidawave kaleidawave added this to the 0.1.0 milestone Jun 23, 2023
@kaleidawave kaleidawave removed the feedback-needed Extra attention/consensus is needed label Jan 5, 2024
@kaleidawave
Copy link
Owner Author

Won't go into too much detail here but

  • Lookup generics have solved type parameters of collection types
  • User created Promise is a Type::SpecialObject and will get a special implementation

Still to implement before closing

  • Lookup generics for Set and Map

@PatrickLaflamme
Copy link
Contributor

@kaleidawave - Is this covered in your currently open PRs? If not I'd like to take a stab at it.

@kaleidawave
Copy link
Owner Author

Yeah I hopefully will get Set, Map and Promise type structure working in #146. After that this issue should be finished

@kaleidawave kaleidawave added the blocking These issues are blocking the checker being used in projects label Jun 20, 2024
@kaleidawave kaleidawave changed the title Type of arrays and other collection types Look generics for collection types & more Jun 20, 2024
@kaleidawave
Copy link
Owner Author

Didn't happen in #146.

There exists a mechanism called "lookup/computed generics". It works for subtyping and other places.

Lookup generics is manually set, it would be good if it could infer for any array (via trying to find a member, preferable contravariant else covariant for some edge cases).

Will test for Map & Set soon.

Proxy is a different issue #33 and Promises are different #168

@kaleidawave kaleidawave changed the title Look generics for collection types & more Lookup/computed generics for collection types & more Jun 20, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
blocking These issues are blocking the checker being used in projects checking Issues around checking subtyping Related to comparing two types
Projects
None yet
Development

No branches or pull requests

2 participants