Kipper
Kipper copied to clipboard
[Feature] Implement type unions `T1 | T2 | T3 ... Tn`
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
Implement support for union types, which allow declarations to have more complex types and be used in more complex situations.
The syntax for unions would be:
T1 | T2 | T3 | ... | Tn
Where n
would be any desired value i.e. there is no compiler-enforced limit of the maximum amount of unioned types.
For example:
def func(value: num | str) -> num {
// Convert the value if it is of type 'str'
if (typeof(value) == str) {
value = value as str;
}
return value * value;
}
Exact behaviour / changes you want
- [ ] Implement union-type syntax allowing multiple types for any declaration.
- [ ] Implement internal compiler support for type unions, so they are properly handled in all cases i.e. enforced to be narrowed down to a single type if a specific use case requires it.
- [ ] Implement proper type translation to TypeScript.
Related issues
- #369
- #495
- #705