I'm struggling to articulate my problem, so I think the best way to convey it is through a minimal example. Take a look below:
type Result = {
prop1: {
val1: number,
val2: string
},
prop2: {
val1: number
}
};
function somefn<T extends Result>(): Partial<T['prop1']> {
return({val1: 1}); // <- Error: Type '{ val1: 1; }' is not assignable to type 'Partial<T["prop1"]>'.ts(2322)
}
Why isn't {val1: 1}
recognized as a valid Partial<T['prop1']>
for any T? Shouldn't it be? Any type that extends Result should have prop1.val1: number. Or am I missing something here?
Edit: Regarding the narrowing of numbers - why does the following code not throw an error?
type Result = {
prop1: {
val1: number
},
prop2: {
val1: number
}
};
function somefn<T extends Result>(): Partial<T['prop1']> {
return({val1: 1});
}
When val1 is the only property, it seems to accept it without any issue.