Consider this class:
class MyObject {
myVar: string;
}
When I initially construct MyObject, myVar field will be set to an undefined, yet when I try to set the variable to an undefined, it will complain. I understand that I can pipe the myVar to allow undefined like myVar: string | undefined;
const obj: MyObject = new MyObject();
console.log(obj.myVar); // undefined
console.log(typeof obj.myVar === 'undefined'); // true
obj.myVar = undefined; // not allowed
To me, the purpose of not allowing an undefined is to indicate that this variable can never be undefined. But clearly that is not true. So then, what is the purpose of not allowing us to set it to an undefined?