Issue
type ValidValue = 'X' | 'Y';
type MyType = {
arr: ValidValue[];
}
How to enforce arr
to have as max length N
(2 in this case, because we have 2 valid distinct values)
Solution
Typescript has fixed size array which called as tuple you can use optional element in tuple like this
let t: [number, string?, boolean?];
t = [42, "hello", true];
t = [42, "hello"];
t = [42];
also, this answer had more details about fixed-size arrays and you can find about typescript Types in here.
Answered By - Buddhika Prasadh
0 comments:
Post a Comment
Note: Only a member of this blog may post a comment.