Comment

Comment by myfonj

As a side note, in editors using js/ts language server from VSCode, you can benefit from these types even in "vanilla" JavaScript with JSDoc. It could look like:

    // @ts-check
    /// <reference path="./ts-reset-0.3.7/src/entrypoints/recommended.d.ts"/>
    // = contents of the archive from
    // https://github.com/total-typescript/ts-reset/releases
    
    const allCurrencies = /** @type {const} */(["EUR", "USD"]);
    /**
     * @typedef {typeof allCurrencies[number]} currency
     */
    
    allCurrencies.includes('XXX');
    // No 'Argument of type '"XXX"' is not assignable…' error any more.
    // Would be that error without ts-reset.
    
    /** @type {currency} */
    let foo = 'EUR'; // OK
    /** @type {currency} */
    let bar = 'XXX'; // that error, expected
parent myfonj 3 years ago

Discussion

Live from the official Hacker News API

A modern reader for Hacker News · SvelteKit + Skeleton