eslint-plugin-functional icon indicating copy to clipboard operation
eslint-plugin-functional copied to clipboard

Autofix on TypeScript mapped types with `-readonly` cause syntax error

Open maxpatiiuk opened this issue 3 years ago • 1 comments

Bug Report

I have the following code:

export type Writable<T> = {
  -readonly [K in keyof T]: T[K];
};

ESLint reports "functional/prefer-readonly-type" rule and an option to "--fix" it.

Expected behavior

Autofix should remove -:

export type Writable<T> = {
  readonly [K in keyof T]: T[K];
};

Actual behavior

Autofix creates a syntax error:

export type Writable<T> = { readonly
  -readonly [K in keyof T]: T[K];
};

Steps to reproduce

ESLint config:

{
  // ...
  plugins: [
    // ...
    'functional',
    // ...
  ],
  extends: [
    // ...
    "plugin:functional/external-recommended",
    "plugin:functional/recommended",
    "plugin:functional/no-object-orientation",
    "plugin:functional/no-statements",
    "plugin:functional/no-exceptions",
    "plugin:functional/currying",
    "plugin:functional/stylistic",
    // ...
  ],
// ...
}

Proposed changes

Either disable autofix for -readonly, or hande it properly.

See https://github.com/microsoft/TypeScript/pull/21919

maxpatiiuk avatar Jul 18 '22 03:07 maxpatiiuk

I believe the correct behavior should be for it to not try and auto fix this at all.

RebeccaStevens avatar Jul 18 '22 04:07 RebeccaStevens