Closed
Description
TypeScript Version: 2.4.2
Code
interface AddTodoAction {
type: 'ADD_TODO'
id: number
text: string
}
interface ToggleTodoAction {
type: 'TOGGLE_TODO'
id: number
}
type TodosAction = AddTodoAction | ToggleTodoAction
const action = {
type: 'TOGGLE_TODO',
id: 1
}
const target: TodosAction = action
^^^^^^
// or
const fun = (a: TodosAction) => {
}
fun(action)
^^^^^^
Expected behavior:
No error.
Actual behavior:
error TS2345: Argument of type '{ type: string; id: number; }' is not assignable to parameter of type 'TodosAction'.
Type '{ type: string; id: number; }' is not assignable to type 'ToggleTodoAction'.
Types of property 'type' are incompatible.
Type 'string' is not assignable to type '"TOGGLE_TODO"'.