Issue
Is there a way without type hinting to create a tuple in Typescript.
If I simply do
const tuple = [1, 2];
the type of Tuple number[]
The closest I can get to a oneliner is
const tuple: [number, number] = [1, 2];
Am I missing something, or is this the only way?
Solution
As of TypeScript 3.4, you can add simply as const at the end.
const tuple = [1, 2] as const;
Full credit to @bela53's answer, which has a better example and link to TS playground.
Answered By - Jay Wick
0 comments:
Post a Comment
Note: Only a member of this blog may post a comment.