Is there a way to declare a choice? Like either this or that. #2256
-
Say I want a model to be of this type: type Ingredient = {
productId: number;
} & (
| {
servingId: number;
amount: number;
}
| {
weight: number;
}
); samples: const ingrWithServing: Ingredient = {
productId: 1,
servingId: 1,
amount: 10,
};
const ingrWithWeight: Ingredient = {
productId: 1,
weight: 100,
}; Now how to refactor the const ingredientModel = types.model({
productId: types.number,
servingId: types.number,
amount: types.number,
weight: types.number,
}); |
Beta Was this translation helpful? Give feedback.
Answered by
coolsoftwaretyler
Mar 27, 2025
Replies: 1 comment
-
You probably want a union type here. |
Beta Was this translation helpful? Give feedback.
0 replies
Answer selected by
coolsoftwaretyler
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
You probably want a union type here.