Skip to content

Commit 72ad6ad

Browse files
committed
strengthen type on first element
1 parent e31d791 commit 72ad6ad

File tree

2 files changed

+3
-1
lines changed

2 files changed

+3
-1
lines changed

src/index.d.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,6 @@
22
// N is the length of the array
33
// T is the type of array elements
44
export type FixedSizeArray<N extends number, T> = N extends 0 ? never[] : {
5-
0: any;
5+
0: T;
66
length: N;
77
} & ReadonlyArray<T>;

src/test.ts

+2
Original file line numberDiff line numberDiff line change
@@ -4,11 +4,13 @@ let d: FixedSizeArray<2, string>;
44

55
d = ['a', 'b']; // ok
66
d[0] = 'a2'; // ok
7+
d[0] = 0; // type error
78
d[1] = 'b2'; // type error, but it is wrong!
89
d[2] = 'c2'; // type error
910
d = ['a']; // type error
1011
d = ['a', 'b', 'c']; // type error
1112
d = ['a', true]; // type error
13+
d = [true, 'a']; // type error
1214

1315
d.push('d'); // type error
1416

0 commit comments

Comments
 (0)