Rule proposal: typescript tuples should use []
and arrays .at()
for accessing members
#6936
Closed
6 tasks done
Labels
enhancement: new plugin rule
New rule request for eslint-plugin
package: eslint-plugin
Issues related to @typescript-eslint/eslint-plugin
wontfix
This will not be worked on
Before You File a Proposal Please Confirm You Have Done The Following...
My proposal is suitable for this project
Description
There should be a rule that allows enforcing arrays to use
array.at(0)
to access it's members, while allowing tuples to usetuple[0]
(bracket notation) to do so.This is useful since using bracket notation on an array of type
T
can returnundefined
if the number is out of range, but the type that typescript returns is onlyT
.Using
.at()
correctly informs the developer about this.This is not true on tuples, where given a tuple of type
[X, Y]
accessing the parameters with bracket notation should return something of typeX
orY
.Currently there is no rule to enforce this, and I could not find a way to implement this as a custom rule either.
Fail Cases
Pass Cases
Additional Info
No response
The text was updated successfully, but these errors were encountered: