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] - expand typedef - combine multiple types into a new type #2750

Closed
dinbtechit opened this issue Jan 1, 2023 · 1 comment
Closed
Labels
feature Proposed language feature that solves one or more problems state-duplicate This issue or pull request already exists

Comments

@dinbtechit
Copy link

It would be nice if we could expand typedef to combine multiple types into a new type, similar to typescript.

Current Scenario

dynamic getIntOrDouble() {
  // this method can return either Int or double. 
  // But it could also return anything and the compiler would not complain about it.
}

Proposed Scenario

Pseudo Code:

typedef MyNumber = int | double;

Usage:

MyNumber getIntOrDouble() {
 // Now this must return an int or a double. Or else you get a compile error.
}
@dinbtechit dinbtechit added the feature Proposed language feature that solves one or more problems label Jan 1, 2023
@lrhn lrhn added the state-duplicate This issue or pull request already exists label Jan 2, 2023
@lrhn
Copy link
Member

lrhn commented Jan 2, 2023

That sounds like union types: #1222.

@lrhn lrhn closed this as completed Jan 2, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
feature Proposed language feature that solves one or more problems state-duplicate This issue or pull request already exists
Projects
None yet
Development

No branches or pull requests

2 participants