I am facing a scenario with various types:
export type a = {
todo: string;
};
export type b = {
id: number;
};
export type TodosAction = Action<string> & (a | b);
In addition, I have a function defined as follows:
function doSmth(action:TodosAction){
switch(action.type){
case "a":
action.todo //TS error, doesn't exist
(action as a).todo // Works fine this way
}
}
The main concern is regarding accessing the todo
property without needing to typecast using as
.
Edit:
type Action<T>={
type:T;
}