this post was submitted on 29 Jul 2025
-1 points (44.4% liked)
Programming
14145 readers
5 users here now
All things programming and coding related. Subcommunity of Technology.
This community's icon was made by Aaron Schneider, under the CC-BY-NC-SA 4.0 license.
founded 2 years ago
MODERATORS
you are viewing a single comment's thread
view the rest of the comments
view the rest of the comments
You have two options depending on how you set your Typescript config.
Option 1, the default:
Option 2, using the
noUncheckedIndexedAccess
setting:Your AI assistant appears to assume option 2. Maybe you have that option enabled in your project?
I'm sorry you had to spend a lot of time and frustration on this problem. But fundamentally Rust and Typescript have the same limitation: neither will catch out-of-bounds access errors on variable-length collections at type-checking time. They don't have the necessary information to do that.
Rust can catch out-of-bounds access on a fixed-length array if you use a literal number for the index access. But Typescript can do the same thing if you use a fixed-length tuple type (e.g.
[number, number]
instead ofnumber[]
).