TypeScript Version: 2.6.2
Code
enum ActionType {
Call
}
interface Action {
type: ActionType;
}
interface CallAction extends Action {
context: any;
}
class Service {
exec<T extends Action>(action: T) {
if (action.type == ActionType.Call) {
(<CallAction>action).context = {};
}
}
}
Expected behavior:
I should use cast because CallAction extends Action
Actual behavior:
I have the following compilation error:
(<CallAction>action).context = {};
Type 'T' cannot be converted to type 'CallAction'.
Type 'T' cannot be converted to type 'CallAction'.
Type 'Action' is not comparable to type 'CallAction'.
Property 'context' is missing in type 'Action'.
TypeScript Version: 2.6.2
Code
Expected behavior:
I should use cast because CallAction extends Action
Actual behavior:
I have the following compilation error: