I wonder why I can provide different generic interface in configure()
method than in my class
? In the first no error
example, I provide IType<Args1>
as a generic type for MyClass
and then I can simply override it by IArgs2
that has a prop missing and I didn't get any error. Is it any way to ensure the types are exactly the same?
interface IArgs1 {
a: string;
b: string;
}
interface IArgs2 {
a: string;
}
interface IArgs3 {
d: string;
}
interface IType<T> {
configure(args: T): void
}
// no error - even if 'b' is missing from IArgs2
class Class implements IType<IArgs1> {
configure(args: IArgs2) {}
}
// error - because it's missing all IArgs1 attributes
class MyClass implements IType<IArgs1> {
configure(args: IArgs3) {}
}