-
Notifications
You must be signed in to change notification settings - Fork 13.1k
Closed
Labels
DuplicateAn existing issue was already createdAn existing issue was already created
Description
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" //wrongThe 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
disjukr, justinbc820, Kasahs, Spiralis, RafaelSalguero and 6 morejanekeilts
Metadata
Metadata
Assignees
Labels
DuplicateAn existing issue was already createdAn existing issue was already created