eslint-plugin-total-functions
eslint-plugin-total-functions copied to clipboard
New rule: ban index signatures entirely
Index signatures lead to all sorts of unsoundness and you're better off using a real Map in almost every case.
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.
First, my deep appreciation. Fantastic eslint plugin :)
I noticed that there is still a problem with this code
get scoreValueSingle(): ScoreValueType | null {
const values: ScoreValueType | undefined = this.scoreValue[0];
return values;
}
TS said that the variable "values" is ScoreValueType. Which is obviously wrong :/
Thanks for the kind words @szagi3891 . What you describe is a good catch (thanks!) but it's a separate issue to the one in this ticket. I've created https://github.com/danielnixon/eslint-plugin-total-functions/issues/68 for the issue you describe. PR welcome ;-)
I think I found the reason. I submitted a PR :) https://github.com/danielnixon/eslint-plugin-total-functions/pull/69/files
@danielnixon Could you please take a look at it?
This just landed a few hours ago: https://github.com/typescript-eslint/typescript-eslint/commit/d7dc108580cdcb9890ac0539e7223aedbff4a0ed
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)
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.
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