-
-
Notifications
You must be signed in to change notification settings - Fork 679
SwitchOnExtends instead of nested-ternary #1386
Copy link
Copy link
Closed as not planned
Labels
Description
Type description + examples
Nested ternary condition inside Typescript type looks awkward and unreadable
there is even a eslint rule
https://eslint.org/docs/latest/rules/no-nested-ternary
maybe it makes sense to do it SwitchOnExtends with more declarative form:
type KindOf<T> = T extends string
? 'string'
: T extends number
? 'number'
: T extends boolean
? 'boolean'
: T extends any[]
? 'array'
: never;for example converting =>
type KindOf<T> = SwitchOnExtends<
[string, 'string'],
[number, 'boolean'],
[boolean, 'string'],
[any[], 'array'],
never
>or something like that
Type source
No response
Search existing types and issues first
- I tried my best to look for it
Reactions are currently unavailable