Hacker Newsnew | past | comments | ask | show | jobs | submit | tmkn13's commentslogin

Yes there is, you can either use as const or define the type as a tuple:

    const x = [1,2] as const;
    //const x: [number, number] = [1,2];
    const y = x[666];//Tuple type 'readonly [1, 2]' of length '2' has no element at index '666'.
    const z = y + 3;//Object is possibly 'undefined'.
Both versions will error the same.


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

Search: