const abc = <T extends object, P extends { [key in keyof T]?: number }>(
a: T,
b: P
) => {
console.log(a, b);
};
const A = { x: "1", y: "2", z: "3" };
const b = { x: 1, y: 2, z: 3 };
const b1 = { x: 1, y: 2 };
const b3 = { m: 5 };
const b4 = { m: 5, x: 1 };
abc(A, b);
abc(A, b1);
abc(A, b3); // Type '{ m: number; }' has no properties in common with type '{ x?: number | undefined; y?: number | undefined; z?: number | undefined; }'
abc(A, b4); // expect type error just like b3 but it is not
since m
doesn't exist on A
, b4
should error like b3
right? but why it is not error and how to fix it?
here is the sand box codesandbox