Re:Mining my mailbox for top email service providers
by kerkeslager on Wednesday February 19, 2020 @02:30AM
(#22363703)
> ({}).foo returning undefined is exactly what I'd expect. That's a basic part of how accessing properties in Javascript works,
This is an excellent and succinct explanation of why JavaScript is a badly-designed language, and why I use better designed languages when possible.
If the basic properties "work" when it makes no sense for them to work, your language is broken.
> That's what using typed signatures for your objects is for.
Explain more?
Re:Mining my mailbox for top email service providers
by crooked-v on Wednesday February 19, 2020 @07:41PM
(#22371736)
> Explain more?
With Typescript or even just JSdoc and a good IDE, you can do:
const a: {propertyA?: true; propertyB?: 'cats';} = {};
// or
/**
* @type {object}
* @property {true=} propertyA
* @property {'cats'=} propertyB
*/
const a = {};
...and get warnings later when you attempt to access anything that's not propertyA, propertyB, or a JS builtin, as well as warnings if you attempt to use either without verifying whether it's undefined or not, as well as warnings if you then try to use them in places restricted to non-matching types.With Typescript, you can turn on full strictness and make these build-rejecting compile-time errors, too.
> Now imagine hundreds of lines of code and a bunch of asynchronous callbacks occur between the last two lines, and imagine what that does for your debugging experience
That's what using typed signatures for your objects is for. It's not even substantially different from having, say, Java with an object with properties that can be nullable or Optional.empty().