Can someone explain to me why does this compile in Typescript?
class Result<T> {
object: T | null = null;
}
function setOnlyA(res: Result<{ a: number }>) {
res.object = { a: 5 };
}
function setAB(res: Result<{ a: number; b: string }>) {
setOnlyA(res);
// everything compiles fine, but res object is invalid
// at this point according to type definitions
}
I would expect setOnlyA call to be disallowed in setAB. I have strict mode on. Do I need some other setting?