Hacker News new | ask | show | jobs
by crooked-v 2311 days ago
> 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.