Kipper icon indicating copy to clipboard operation
Kipper copied to clipboard

[Feature] Implement type joining `T1 & T2 & T3 ... Tn`

Open Luna-Klatzer opened this issue 5 months ago • 0 comments

Is there an existing proposal for this?

  • [X] I have searched the existing issues

This feature does not exist in the latest version

  • [X] I am using the latest version

Proposal

Like discussed in #705, there is a need for type narrowing in the form of joining two or more types together in specific if-statement or conditional branches. To allow for this feature to work, there needs to be type joining i.e. all the types being joined together to form a more narrowed type than any single part. This is different from unions, as unions give options for types, while they are mixed together meaning something can be str | obj but not both at the same time.

For example:

if (val matches Int1 && val matches Int2) {
  // -> val: Int1 & Int2
} 

Exact behaviour / changes you want

  • [ ] Implement internal type joining where narrowed types are being automatically mapped to a narrowed type T1 & T2 & T3 ... Tn.
  • [ ] Implement syntactical type joining where a user can specify a narrower type.
  • [ ] Implement proper type translation to TypeScript.

Related issues

  • #705

Luna-Klatzer avatar Sep 25 '24 19:09 Luna-Klatzer