I encountered an error when trying to use Partial<T>
in this scenario:
type WithName = {
name: string
}
function test<T extends WithName>(x: T) {
// Error: Type '{ name: "a"; }' is not assignable to type 'Partial<T>'.
let a: Partial<T> = {
name: 'a'
}
// Error: Type '{ name: "a"; }' is not assignable to type 'Partial<T>'.
merge<T>(x, {name: 'a'})
}
declare function merge<T>(a: T, b: Partial<T>): T
Is it a typescript limitation?
It works correctly with spread syntax: {...x, name: 'a'}
, but I want to use a custom merge function.