Skip to content

New option ignore-interface-prefix on readonly-keyword rule #123

@jonaskello

Description

@jonaskello

Today we can ignore prefix on interface members using readonly-keyword with ignore-prefix. Sometimes (for performance reasons) I would like to create an interface where all members are mutable. In those cases it might be helpful to be able to prefix the interface name with something that is ignored (instead of prefixing each member). For example:

interface MutablePerson {
  firstName: string
  lastName: string
}

Currently readonly-keyword will warn on this interface. My suggestion is that we add an option like ignore-interface-prefix for the readonly-keyword and if I set that to Mutable the above will not warn.

I'm not sure this is a totally good idea since it will be easier to write mutable interfaces using this option. However I find some parts of my code needs to be in fully mutable mode in order to get good performance.

Another way around this is to have a Mutable<T> type mapping that removes the readonly attributes:

type Mutable<T> = { -readonly [P in keyof T]: T[P] };

interface Person {
  readonly firstName: string
  readonly lastName: string
}

type MutablePerson = Mutable<Person>;

Metadata

Metadata

Assignees

No one assigned

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions