我在 TypeScript 中写了一些代码:
type Point = {
x: number;
y: number;
};
function getThing<T extends Point>(p: T): Partial<T> {
// More interesting code elided
return { x: 10 };
}
Run Code Online (Sandbox Code Playgroud)
这会产生一个错误:
Type '{ x: 10; }' is not assignable to type 'Partial<T>'
这似乎是一个错误 -{ x: 10 }显然是一个Partial<Point>. TypeScript 在这里做错了什么?我该如何解决?