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

Rule prefer-immutable-types doesn't work with fp-ts Types #525

Closed
ldrick opened this issue Jan 29, 2023 · 2 comments
Closed

Rule prefer-immutable-types doesn't work with fp-ts Types #525

ldrick opened this issue Jan 29, 2023 · 2 comments
Labels
Resolution: External It was a real bug, but not in the code in this repo. Type: Bug Inconsistencies or issues which will cause a problem for users or implementors.

Comments

@ldrick
Copy link

ldrick commented Jan 29, 2023

Bug Report

If you use fp-ts ReadonlyNonEmptyArray (https://gcanti.github.io/fp-ts/modules/ReadonlyNonEmptyArray.ts.html) like this:

import {readonlyNonEmptyArray as RNEA} from 'fp-ts';

const myMethod= (
	values: RNEA.ReadonlyNonEmptyArray<number>,
): RNEA.ReadonlyNonEmptyArray<string> => RNEA.map(/* some code*/)(values)

Expected behavior

The parameter values: RNEA.ReadonlyNonEmptyArray<number> should be detected as being immutable.

Actual behavior

The parameter values: RNEA.ReadonlyNonEmptyArray<number> gets marked as being mutable.
Rewriting the above to somehow fixes the error, but looks not quite right:

import {readonlyNonEmptyArray as RNEA} from 'fp-ts';

const myMethod= (
	values: Readonly<RNEA.ReadonlyNonEmptyArray<number>>,
): RNEA.ReadonlyNonEmptyArray<string> => RNEA.map(/* some code*/)(values)

Steps to reproduce

use above sample

Proposed changes

Maybe, as I don't know the details, somehow check, if the Type is a superior Type of immutable types?

@ldrick ldrick added Status: Triage This issue needs to be triaged. Type: Bug Inconsistencies or issues which will cause a problem for users or implementors. labels Jan 29, 2023
@RebeccaStevens
Copy link
Collaborator

Looks like this is a bug in the upstream library. I've open an issue for it over there (is-immutable-type#40).

In the meantime, one possible work around is to use an immutability override to mark ReadonlyNonEmptyArray as ReadonlyShallow:

"settings": {
  "immutability": {
    "overrides": [
      {
        "name": "ReadonlyNonEmptyArray",
        "to": "ReadonlyShallow",
        "from": "Mutable"
      }
    ]
  }
}

@RebeccaStevens RebeccaStevens added Resolution: External It was a real bug, but not in the code in this repo. and removed Status: Triage This issue needs to be triaged. labels Jan 30, 2023
@RebeccaStevens
Copy link
Collaborator

Fixed in the upstream now.

RebeccaStevens added a commit that referenced this issue Feb 2, 2023
update dependency is-immutable-type to v1.2.4

re #525
github-actions bot pushed a commit that referenced this issue Feb 2, 2023
## [5.0.1](v5.0.0...v5.0.1) (2023-02-02)

### Bug Fixes

* improve calculation of immutability involving intersections ([75cd708](75cd708)), closes [#525](#525)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Resolution: External It was a real bug, but not in the code in this repo. Type: Bug Inconsistencies or issues which will cause a problem for users or implementors.
Projects
None yet
Development

No branches or pull requests

2 participants