When I use the following code, typescript does not complain that I try to pass IAction<Product> instead of the expected IAction<Customer>:
interface IAction<T> {
canExecute<T>(input: T): void;
}
interface Product {
name: string,
}
interface Customer {
displayName?: string;
description?: string;
}
class MyAction implements IAction<Product> {
public canExecute<Product>(product: Product): void {
}
}
class MyMenuItemAction {
constructor(private action: IAction<Customer>) {
}
}
function foo(action: IAction<Customer>): void {
}
const action: IAction<Product> = new MyAction();
const menuItem = new MyMenuItemAction(action);
foo(action);
But if I remove the <T> from the canExecute function in the IAction interface, it does complain about it:
interface IAction<T> {
canExecute(input: T): void;
}
Is this a bug in typescript?