eslint-plugin-total-functions icon indicating copy to clipboard operation
eslint-plugin-total-functions copied to clipboard

New rule: ban index signatures entirely

Open danielnixon opened this issue 4 years ago • 7 comments

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

danielnixon avatar Aug 30 '20 01:08 danielnixon

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.

danielnixon avatar Aug 31 '20 19:08 danielnixon

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 :/

szagi3891 avatar Sep 02 '20 09:09 szagi3891

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 ;-)

danielnixon avatar Sep 02 '20 23:09 danielnixon

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?

szagi3891 avatar Sep 03 '20 03:09 szagi3891

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)

danielnixon avatar Sep 29 '20 00:09 danielnixon

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 avatar Sep 29 '20 01:09 danielnixon

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

danielnixon avatar Mar 07 '23 23:03 danielnixon