Closed
Description
TypeScript Version: 2.1.6
The subject is a bit difficult to write, but look in the code inside method
.
{ id: 1 }
should be implicit convertible to Partial<T>
as T extends { id: number }
.
interface Intf<T extends { id: number }>
{
find: (obj: Partial<T>) => T;
}
interface Obj
{
id: number;
name: string;
}
const intf: Intf<Obj> = {
find(obj: Obj)
{
return obj;
}
}
intf.find({ id: 1, name: '' }); // ok
intf.find({ id: 1 }); // ok
class Component<T extends { id: number }>
{
constructor (public intf: Intf<T>)
{
}
method()
{
this.intf.find({ id: 1 } as T); // ok
this.intf.find({ id: 1 }); // error! why?
}
}
const component = new Component<Obj>(intf);
component.intf.find({ id: 1, name: '' }); // ok
component.intf.find({ id: 1 }); // ok