Consider the following scenario:
type ActionType =
'action1' |
'action2' |
'action3';
interface Action {
type: ActionType;
value?: number | Date;
}
Is there a method in typescript to enforce restrictions on the value
type based on the type
value?
For instance, if type
is either action1
or action2
, I would like the value
field to only accept values of type number
, whereas if type
is action3
, then value
should be of type Date
.
Although it may not be feasible, it doesn't hurt to ask.