Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Autofix on TypeScript mapped types with -readonly cause syntax error #384

Closed
maxpatiiuk opened this issue Jul 18, 2022 · 1 comment · Fixed by #480
Closed

Autofix on TypeScript mapped types with -readonly cause syntax error #384

maxpatiiuk opened this issue Jul 18, 2022 · 1 comment · Fixed by #480
Labels
Accepted This issue or PR has been accepted. Type: Bug Inconsistencies or issues which will cause a problem for users or implementors.

Comments

@maxpatiiuk
Copy link

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 microsoft/TypeScript#21919

@maxpatiiuk maxpatiiuk added Status: Triage This issue needs to be triaged. Type: Bug Inconsistencies or issues which will cause a problem for users or implementors. labels Jul 18, 2022
@RebeccaStevens RebeccaStevens added Accepted This issue or PR has been accepted. and removed Status: Triage This issue needs to be triaged. labels Jul 18, 2022
@RebeccaStevens
Copy link
Collaborator

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Accepted This issue or PR has been accepted. Type: Bug Inconsistencies or issues which will cause a problem for users or implementors.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants