TypeScript Version: 2.3.2
Code
typeAction={type: 'activate'}|{type: 'disactivate'};functiondispatchAction(action: Action): void{}constactive=true;dispatchAction({type : (active? 'disactivate' : 'activate')});Expected behavior:
Everything is correct. And if I change last line to:
dispatchAction(active? {type : 'disactivate'} : {type : 'activate'});then no errors will be produced.
Actual behavior:
Error:
Argument of type '{ type: "activate" | "disactivate"; }' is not assignable to parameter of type 'Action'.
Type '{ type: "activate" | "disactivate"; }' is not assignable to type '{ type: "disactivate"; }'.
Types of property 'type' are incompatible.
Type '"activate" | "disactivate"' is not assignable to type '"disactivate"'.
Type '"activate"' is not assignable to type '"disactivate"'.
TypeScript Version: 2.3.2
Code
Expected behavior:
Everything is correct. And if I change last line to:
then no errors will be produced.
Actual behavior:
Error:
Argument of type '{ type: "activate" | "disactivate"; }' is not assignable to parameter of type 'Action'.
Type '{ type: "activate" | "disactivate"; }' is not assignable to type '{ type: "disactivate"; }'.
Types of property 'type' are incompatible.
Type '"activate" | "disactivate"' is not assignable to type '"disactivate"'.
Type '"activate"' is not assignable to type '"disactivate"'.