Should TS infer the correct type of a property in an object based on an in check?
type test = {
name?: string | undefined;
};
type test2 = {
name?: string;
};
declare const kTest: test;
declare const kTest2: test2;
if('name' in kTest) {
const myVar = kTest['name']; // myVar is of type: string | undefined
}
if('name' in kTest2) {
const myVar2 = kTest2['name']; // myVar is of type: string | undefined
}
Shouldn't myVar2 be of type string, and not string | undefined based on the in operator check?
In other words, the ? operator in a type should resolve to T rather than T | undefined given an in operator check