Open
Description
openedon Nov 18, 2020
Search Terms
type defination, functional type defination, meta, meta programming, dynamic type declaration
Suggestion
Write a function to define types.
Use Cases
Build a more complex type.
Examples
type MyType<T extends string>{
if(T extends 'a'){
return 'a' //type 'a'
}
if(T extends 'b'){
return 'b' //type 'b'
}
return string
}
Checklist
My suggestion meets these guidelines:
- [x ] This wouldn't be a breaking change in existing TypeScript/JavaScript code
- [x ] This wouldn't change the runtime behavior of existing JavaScript code
- [x ] This could be implemented without emitting different JS based on the types of the expressions
- [x ] This isn't a runtime feature (e.g. library functionality, non-ECMAScript syntax with JavaScript output, etc.)
- [x ] This feature would agree with the rest of TypeScript's Design Goals.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment