Repository navigation
Suggestion:Validation on defined types #8665
Description
Activity
Looks like the same thing as #6579. i would add implementation suggestions in that issue instead of creating a new one.
Reacted by Va Da, Stephen Zhao, Atis Straujums and Janek Eilts UG (haftungsbeschränkt)Reacted by JongChan Choi (Rieul), Zev Spitz, Va Da, Pat Myron and Janek Eilts UG (haftungsbeschränkt)- addedDuplicateAn existing issue was already createdAn existing issue was already created
on May 18, 2016 Sorry, I thought that should be in a different issue because the other was just about allow regex patterns in types and I'm asking for a more general feature, but I will suggest there.
Thank you!
Reacted by Zev Spitz, Rafael Salguero Iturrios, Atis Straujums, Pat Myron and Janek Eilts UG (haftungsbeschränkt)Mohamed Hegazy (@mhegazy) Is this a duplicate of #6579? The first and third examples could be covered by #6579 but the middle example is not regex based. Furthermore, for the first example, the integer check could (and probably should) be implemented without a regex:
type Integer (n: number) => Math.floor(n) == n; let x:Integer = 3 //OK let y:Integer = 3.6 //wrongReacted by Daniel, SlurpTheo, Tim van der Horst and Ashlynne MitchellPlease see #4639
Mohamed Hegazy (@mhegazy) If I understand you correctly, the OP provides three examples:
Integer, duplicated in #4639;ColorLevelwhich could be covered by a combination of #15480 and #4639; andHexwhich is covered by #6579.Are there no other possible type validations possible with this?
type Even (n: number) => n % 2 == 0; type Past (dte: Date) => dte < Date.now();Reacted by Janek Eilts UG (haftungsbeschränkt)Mohamed Hegazy (@mhegazy) Considering that the OP's comment on #6579 has (as of this writing) garnered 67 +1s, and this proposal is broader than any of the other more limited special case proposals, can this be reopened?
Reacted by Felipe Marinho, Ivan Shmidt, mewalig, odusseys, Alvin Ramskogler and Janek Eilts UG (haftungsbeschränkt)Reacted by Janek Eilts UG (haftungsbeschränkt)These are called Dependent Types: https://en.wikipedia.org/wiki/Dependent_type
A very powerful feature indeed, especially if done generically as opposed to case-by-case (regex, range types, etc). If pursued in this form, we would need to be wary of what is or is not allowed in such type predicates (e.g. no type system within the type predicate), since this could lead to undecidable type checking...
Reacted by mewalig, Rafael Salguero Iturrios, Ashlynne Mitchell, Andreas Källberg, Sahand Akbarzadeh, AA, Alvin Ramskogler, Edoardo Barbieri and Janek Eilts UG (haftungsbeschränkt)- locked as resolved and limited conversation to collaborators
on Oct 22, 2025
It would be nice if we could write some kind of validation on user defined types. Something like:
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