I apologize for such a generic question title, but I really don't know how to describe my question in short.
Here is the case:
type Data = {
id: number
name: string
}
function func(): Partial<Data> {
return { name: '' } // ok
}
function wrap<T extends Data>() {
function func(): Partial<T> {
return { name: '' } // Type '{ name: ""; }' is not assignable to type 'Partial<T>'
}
}
The error in second case is a complete mystery for me.
As I know so far, the extends
in the function constains T to be a subtype of the specified type. And, as I understand – whatever is subtype of my Data
type, it must have id: number
and name: string
, is it correct?
And if it is – then what's wrong with { name: '' }
as Partial<T>
?