Hacker News new | ask | show | jobs
by scottlecrab 2415 days ago
https://www.typescriptlang.org/play/index.html#code/MYewdgzg...

Using `as const` will report both the 2nd and 3rd lines as type errors. You've been able to do this in TypeScript for a while even before they introduced the `as const` syntax.

1 comments

Thanks, you can still trick it with this though (there's no type error):

    const x = [1, 2] as const;
    const r = 666 + 1;
    const y = x[r];
    const z = y + 3;
Let's wait until TS supports dependent types!