selfrefactor / rambda

Faster and smaller alternative to Ramda
https://selfrefactor.github.io/rambda
MIT License
1.65k stars 89 forks source link

Chaining does not work with DeepReadonly when upgrading to 7.0.1 #617

Closed corneliusgdahling closed 2 years ago

corneliusgdahling commented 2 years ago

Hello,

I am not entirely sure why it happens, but after upgrading to Rambda 7.0.1, a function which chains a DeepReadOnly value, creates a type error.

I have a sandbox example which looks similar to the one in my project, but you only need to look at line 22 to see that chaining a value which is DeepReadOnly, creates a type error. Sandbox: Chain with new Rambda. This worked fine with 6.9.0, as that is the current version our project is running, and I found this error while debugging a Dependabot update.

Thanks for your help.

selfrefactor commented 2 years ago

7.0.1 doesn't change much in R.chain typings as only a redundant declaration is removed.

The typings test of R.chain would work if we change source/tsconfig.json to use immutable Rambda typings:

{
  "compilerOptions": {
    "baseUrl": ".",
    "lib": ["es2015", "dom"],
    "module": "CommonJS",
    "noEmit": true,
    "noImplicitAny": true,
    "noImplicitThis": true,
    "noUnusedLocals": true,
    "skipLibCheck": true,
    "strictFunctionTypes": true,
    "strictNullChecks": true,
    "target": "es2015",
    "paths": { "rambda": ["../immutable.d.ts"] }
  }
}

With this setting, R.chain test with your example doesn't produce an error:

  it('happy', () => {
    interface PlayerInterface {
      name: string;
      kitNumber: number;
    }

    interface TeamInterface {
      players: PlayerInterface[];
    }
    type EnhancedTeamInterface = DeepReadonly<TeamInterface>;

    const testChaining = chain((team: EnhancedTeamInterface) => team.players);
  })

The same goes for your example, where using import * as R from "rambda/immutable"; will fix your issue.

corneliusgdahling commented 2 years ago

Alright. Thank you very much for the quick reply. I got the code working with importing from /immutable. I thought Rambda by default was immutable. Is it not?

selfrefactor commented 2 years ago

There was related issue https://github.com/selfrefactor/rambda/issues/565 that brought into light the issue with using readonly, so we have decided to remove it completely from the default typings and only allow it optionally via rambda/immutable. I will close the issue as you have confirmed that it works for you.