We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
1 parent e31d791 commit 72ad6adCopy full SHA for 72ad6ad
src/index.d.ts
@@ -2,6 +2,6 @@
2
// N is the length of the array
3
// T is the type of array elements
4
export type FixedSizeArray<N extends number, T> = N extends 0 ? never[] : {
5
- 0: any;
+ 0: T;
6
length: N;
7
} & ReadonlyArray<T>;
src/test.ts
@@ -4,11 +4,13 @@ let d: FixedSizeArray<2, string>;
d = ['a', 'b']; // ok
d[0] = 'a2'; // ok
+d[0] = 0; // type error
8
d[1] = 'b2'; // type error, but it is wrong!
9
d[2] = 'c2'; // type error
10
d = ['a']; // type error
11
d = ['a', 'b', 'c']; // type error
12
d = ['a', true]; // type error
13
+d = [true, 'a']; // type error
14
15
d.push('d'); // type error
16
0 commit comments