Skip to content

Commit 3ed23c0

Browse files
committed
+ example: access array elements
1 parent f3648f0 commit 3ed23c0

File tree

2 files changed

+14
-0
lines changed

2 files changed

+14
-0
lines changed

README.md

+13
Original file line numberDiff line numberDiff line change
@@ -82,6 +82,19 @@ o = {
8282

8383
## Current problems and limitations
8484

85+
Access to array elements through their indexes will result in a type error.
86+
87+
```javascript
88+
let d: FixedSizeArray<2, string>;
89+
90+
d = ['a', 'b']; // ok
91+
d[0] = 'a2'; // ok
92+
d[1] = 'b2'; // type error, but it is wrong!
93+
d[2] = 'c2'; // type error
94+
```
95+
96+
Other more complex cases.
97+
8598
```javascript
8699
interface Fun<N extends number, M extends number> {
87100
(a: FixedSizeArray<N, number>): FixedSizeArray<M, number>;

src/test.ts

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

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

0 commit comments

Comments
 (0)