One aspect that I find confusing is trying to verify the return type with generics. Take a look at the following code snippet:
interface IT {
name: string;
}
interface check<T> {
get(): Partial<T>;
};
// works
var g: check<IT> = {
get() {
return {
name: 'sdsdf',
error: 'asdad'
}
}
}
// error
var e: check<IT> = {
get() {
return {
name: 123
}
}
}
// error
var f: check<IT> = {
get() {
return {
error: 'asdad'
}
}
}
I'm puzzled as to why, when the return type extends the generic type, it can pass the type check successfully.