Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

New rule: ban index signatures entirely #61

Open
danielnixon opened this issue Aug 30, 2020 · 7 comments
Open

New rule: ban index signatures entirely #61

danielnixon opened this issue Aug 30, 2020 · 7 comments

Comments

@danielnixon
Copy link
Owner

Index signatures lead to all sorts of unsoundness and you're better off using a real Map in almost every case.

@danielnixon
Copy link
Owner Author

This rule should recommend https://immutable-js.github.io/immutable-js/docs/#/Map or TypeScript's ReadonlyMap type if the builtin Map really must be used.

@szagi3891

This comment has been minimized.

@danielnixon

This comment has been minimized.

@szagi3891

This comment has been minimized.

@danielnixon
Copy link
Owner Author

This just landed a few hours ago: typescript-eslint/typescript-eslint@d7dc108

Maybe the best approach here is to teach that rule a new never option (akin to https://github.com/typescript-eslint/typescript-eslint/blob/master/packages/eslint-plugin/docs/rules/consistent-type-assertions.md#assertionstyle)

@danielnixon
Copy link
Owner Author

This is less of an issue now that https://devblogs.microsoft.com/typescript/announcing-typescript-4-1-beta/#no-unchecked-indexed-access is a thing but probably still worth doing.

@danielnixon
Copy link
Owner Author

Even with noUncheckedIndexedAccess, there are other reasons to prefer real Map types: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Map#objects_vs._maps

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants