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

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

Open
2 of 5 tasks
Luna-Klatzer opened this issue Sep 25, 2024 · 0 comments
Open
2 of 5 tasks

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

Luna-Klatzer opened this issue Sep 25, 2024 · 0 comments
Assignees
Labels
feature New feature or enhancement
Milestone

Comments

@Luna-Klatzer
Copy link
Member

Luna-Klatzer commented Sep 25, 2024

Is there an existing proposal for this?

  • I have searched the existing issues

This feature does not exist in the latest version

  • 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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
feature New feature or enhancement
Projects
Development

No branches or pull requests

1 participant