【发布时间】:2022-01-24 03:45:54
【问题描述】:
我用 TypeScript 写了一些代码:
type Point = {
x: number;
y: number;
};
function getThing<T extends Point>(p: T): Partial<T> {
// More interesting code elided
return { x: 10 };
}
这会产生错误:
Type '{ x: 10; }' is not assignable to type 'Partial<T>'
这似乎是一个错误 - { x: 10 } 显然是 Partial<Point>。 TypeScript 在这里做错了什么?我该如何解决这个问题?
【问题讨论】:
标签: typescript generics