HackerTrans
TopNewTrendsCommentsPastAskShowJobs

tmkn13

no profile record

comments

tmkn13
·il y a 7 ans·discuss
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.