Here is a simple illustration:
function doSomething(animal: 'bird' | 'fish'){ }
let flies=true;
const animal = flies ? 'bird' : 'fish'
doSomething(animal);
In the assignment to `animal` from the ternary conditional, TypeScript infers type `'bird' | 'fish'`. (If `animal` were not constant, it would give an error since it would infer type string which is not assignable to 'bird' or 'fish')
However,
const parms = {
animal: flies ? 'bird' : 'fish'
}
doSomething(parms); /* Argument of type '{ animal: string; }' is not
assignable to parameter of type '{ animal: "bird" | "fish"; } */
Here, it infers string from the ternary conditional. Is there a way to maintain this style without defining a type and declaring the field `animal` as that type?