-
-
Notifications
You must be signed in to change notification settings - Fork 2.8k
Closed
Labels
enhancement: new plugin ruleNew rule request for eslint-pluginNew rule request for eslint-pluginpackage: eslint-pluginIssues related to @typescript-eslint/eslint-pluginIssues related to @typescript-eslint/eslint-plugin
Description
Currently there are few ways to declare a dictionary-like type:
// Key can be only `string` and `number`
type _ = { [key: string]: string };
// Key is any type usable as object key
type _ = { [P in string]: string };
// Same as above
type _ = Record<string, string>;
I think it might make sense to implement it as 2 rules:
- Disallow object types (or interfaces) with a single index signature member and fix it to mapped type, or enforce the opposite: disallow mapped types of
string
ornumber
with unused key. - Disallow mapped types with unused key and fix it to
Record
. It also may be extended to enforcing usage of other builtin types, likePartial
orReadonly
. Not sure if there is a need to do the opposite, since it can be done with ban-types.
Akuukis, Zzzen, remcohaszing, yenbekbay, sindresorhus and 2 more
Metadata
Metadata
Assignees
Labels
enhancement: new plugin ruleNew rule request for eslint-pluginNew rule request for eslint-pluginpackage: eslint-pluginIssues related to @typescript-eslint/eslint-pluginIssues related to @typescript-eslint/eslint-plugin