It's very relevant, your TypeScript definition is meaningless at runtime when it's executed JS where all TypeScript's type information is erased, the only checks are relevant are the runtime JS type checks.
> `if (user === undefined || user === null)` is pointless
Right, it is verbose & unecessary, so is only testing for `if (user === undefined)` which is inadequate and I don't know anyone who'd use it since using the recommended `if (user == null)` is shorter and more complete for testing if any value is not `null` or `undefined`. If you're validating JSON you should know that there is no `undefined` type in JSON, but any value could be `null`.
> From my experience, it is much more common to deal with `undefined` in the JS ecosystem, whether that is by omitting properties from objects, or explicitly assigning/returning `undefined` somewhere.
If a type want's to declare that property exists but doesn't have a value it would be `null`, which is also the only option you have in JSON to do so.
Your TypeScript definitions are for your code structure and API description so you can benefit from its static analysis, but you should be aware they do nothing at runtime where all Type annotations are erased so if you try to define your Vue component with an optional property, e.g:
class MyComponent extends Vue
{
p1?:string;
p2 = null;
}
It gets stripped away completely but setting a null value instead will ensure the property exists and is made reactive: var MyComponent = /** @class */ (function (_super) {
__extends(MyComponent, _super);
function MyComponent() {
var _this = _super !== null && _super.apply(this, arguments) || this;
_this.p2 = null;
return _this;
}
return MyComponent;
}
It's important to know what guarantees TypeScript does for you, what effects the type annotations have and what their behavior is at runtime.