Hacker Newsnew | past | comments | ask | show | jobs | submitlogin

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.



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!




Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: