Let's use following string literal as an example:
type Country = "RU" | "US" | "CN"
TL;DR;
The question is: is there any operator that can enforce a certain enum to accept only one possible value? Something like First<Country>
or Single<Country>
.
Reasoning
There is the Exclude
operation which subtracts a set of certain values from another set of possible values. Using Pick
, Omit
, Exclude
, etc. applied on a set of values, a new set of values is returned, which swill allows potentially multiple values.
Usecase I'm interested in: Replace<T, K extends keyof T, NEW>
which replaces a key in T
with a new type NEW
. The K extends keyof T
allows multiple keys on T
. I'm trying to find if it's possible to limit down to define only one possible values (i.e. if more than one passed, TS would throw an error).
If there's no way to limit down the set of allowed values, likely proven, that'd be still a valid answer.