我正在寻找一种在记录字段中具有多态性的类型,以便它接受包含更多字段的记录,并限制所有涉及的记录在这些额外字段中重合:
type foo = { first: string, last: string };
const o = { first: "Foo", last: "Oof", age: 30 };
const p = { first: "Bar", last: "Rab", age: 45 };
const q = { first: "Baz", last: "Zab", gender: "m" };
const main = (o: foo) => (p: foo) => o.first + o.last
// goal
main(o)(p); // type checks
main(o)(q); // type error
这在TS中可能吗?