tslint-immutable icon indicating copy to clipboard operation
tslint-immutable copied to clipboard

Mutable prefix for indexer interfaces

Open jonaskello opened this issue 7 years ago • 1 comments

There is an escape hatch for mutable members of an interface by prefixing them. However this is not useful for indexer interfaces. So I propose to extend the prefix to apply to the interface name too. If the interface name starts with something that is in the ignore-prefix option then ignore it. This would mean that with this config:

"readonly-keyword": [true, {"ignore-prefix": "Mutable"}]

No member of this interface would not be checked:

interface MutableFoo {
  [key: string]: string;
  bar: number
}

jonaskello avatar Feb 20 '18 07:02 jonaskello

Another idea would be to check the name of the indexer key for the prefix:

interface MutableFoo {
  [mutableKey: string]: string; // This is ok because the key is prefixed with mutable
  bar: number // This will give an error as there is no mutable prefix
}

jonaskello avatar Feb 20 '18 07:02 jonaskello