Enhancement: [consistent-indexed-object-style] forbidden from using the "in" keyword in index signature if Record
is preferred
#6598
Labels
accepting prs
Go ahead, send a pull request that resolves this issue
enhancement: plugin rule option
New rule option for an existing eslint-plugin rule
locked due to age
Please open a new issue if you'd like to say more. See https://typescript-eslint.io/contributing.
package: eslint-plugin
Issues related to @typescript-eslint/eslint-plugin
Before You File a Proposal Please Confirm You Have Done The Following...
My proposal is suitable for this project
Link to the rule's documentation
https://typescript-eslint.io/rules/consistent-indexed-object-style/
Description
When
"record"
option is chosen in@typescript-eslint/consistent-indexed-object-style
, we should also be forbidden from using the"in"
keyword in index signature. It's particularly useful for literal types.Here's the justification:
Record
versusIndex Signature
whenever we want to use literal types, as index signature accepts onlystring
,number
orsymbol
as key type.Record
is preferred, it also brings an advantage of ensuring no missing property in literal types -> which further ensures type safety, and avoid getting unexpectedundefined
case from non-existing key.@typescript-eslint/consistent-indexed-object-style
rule allows people using{ [key in Option] : string}
Fail
Pass
Additional Info
No response
The text was updated successfully, but these errors were encountered: