There is the minimum reproducible example:
interface BasicObject {
name: string;
}
interface Object extends BasicObject {
code: string
}
function generic<T extends BasicObject> (options: T) {
// something
}
function externalGeneric<T extends BasicObject>(a: Omit<T, 'name'>) {
generic(a);
}
Could you explain, why Typescript ignores the fact that a
doesn't have name
field and therefore doesn't extend BasicObject
?
The version of Typescript is 4.6.2.
CodePudding user response:
Because you redeclare global Object
interface, try change
interface Object extends BasicObject {
code: string
}
To
interface SomeOtherNameThanObject extends BasicObject {
code: string
}