Sorry for the basic question title, but I'm at a loss for words to describe my query concisely.
Here's the situation:
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 the second scenario is completely puzzling to me.
From what I understand, the extends
keyword in the function constrains T to be a subtype of the specified type. So, if any subtype of my Data
type is required to have id: number
and name: string
, then why doesn't { name: '' }
suffice as Partial<T>
?