Closed
Description
openedon May 18, 2016
It would be nice if we could write some kind of validation on user defined types. Something like:
type Integer(n:number) => String(n).macth(/^[0-9]+$/)
let x:Integer = 3 //OK
let y:Integer = 3.6 //wrong
type ColorLevel(n:number) => n>0 && n<= 255
type RGB = {red:ColorLevel, green:ColorLevel, blue:ColorLevel};
let redColor:RGB = {red:255, green:0, blue:0} //OK
let wrongColor:RGB = {red:255, green:900, blue:0} //wrong
type Hex(n:string) => n.match(/^([0-9]|[A-F])+$/)
let hexValue:Hex = "F6A5" //OK
let wrongHexValue:Hex = "F6AZ5" //wrong
The value that the type can accept would be determined by the function parameter type and by the function evaluation itself. That would solve other issues like #6902, #6579 or #7982
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment