-
Notifications
You must be signed in to change notification settings - Fork 13k
Closed
Labels
UnactionableThere isn't something we can do with this issueThere isn't something we can do with this issue
Description
Search Terms
Custom type validators, pure function validators
Suggestion
having a defined way to document shape / value of a generic type like string , number. This could be a static compile time feature or it can be dragged into runtime.
Use Cases
Avoiding mistakes while creating cache keys
Validators for URLs in form of string
Validators for range
Examples
function url(urlStr: string) {
// Test ur, if okay do nothing, else return error with examples
}
function ipAddress(ipString: string) {
// Test ur, if okay do nothing, else return error with examples
}
const endPoint: string & ( url | ipAddress ) = "0.0.0.0"
Checklist
My suggestion meets these guidelines:
- This wouldn't be a breaking change in existing TypeScript/JavaScript code
- This wouldn't change the runtime behavior of existing JavaScript code
- This could be implemented without emitting different JS based on the types of the expressions
- This isn't a runtime feature (e.g. library functionality, non-ECMAScript syntax with JavaScript output, etc.)
- This feature would agree with the rest of TypeScript's Design Goals.
Metadata
Metadata
Assignees
Labels
UnactionableThere isn't something we can do with this issueThere isn't something we can do with this issue