selfrefactor/rambda

Typescript errors with CRA

alex-pol opened this issue ยท 9 comments

Typescript show errors after updating to 5.10.0
.../node_modules/rambda/_ts-toolbelt/src/Any/_api.ts TypeScript error in .../node_modules/rambda/_ts-toolbelt/src/Any/_api.ts(3,9): Re-exporting a type when the '--isolatedModules' flag is provided requires using 'export type'. TS1205

Project uses CRA (https://github.com/facebook/create-react-app) and isolatedModules flag cannot be disabled.

PR to fix this issue is opened at Rambdax repo - selfrefactor/rambdax#56

I will apply the fix to the pipeline that generates Rambda's local ts-toolbelt.

BTW Github didn't notified me, when you opened this issue and that is the reason for the delay of my response. I saw it when I check issues page of Rambda.

Can you try with the latest release of Rambda by changing to this line in your package.json "rambda": "https://github.com/selfrefactor/rambda#5.12.1-fixed"?

It expect it to work, but your confirmation would be helpful.

Yxwww commented

@selfrefactor , I had the same issue using TS isolatedModules flag and 5.12.1-fixed fixed it.
Thanks !

Thank you @Yxwww for this confirmation. I therefore made a release 5.12.0 that contains the fix. Closing the issue - please reopen if the issue is not solved.

@selfrefactor

Hi, it seems that another error is occurring in the CRA.
I tried with 2 versions of 5.12.1-fixed 6.3.0-beta, but I get the following error.

/node_modules/rambda/_ts-toolbelt/src/ts-toolbelt.ts
TypeScript error in /node_modules/rambda/_ts-toolbelt/src/ts-toolbelt.ts(3,10):
'from' expected.  TS1005

CRA version is v3.4.3.

Thank you @naomei for your report. I am reopening this issue. I'll check the problem and I'll get back to you.

@naomei I just run a test with latest TS CRA and I couldn't reproduce the error.

What I did:

  1. npx create-react-app my-app --template typescript
  2. yarn add rambda
  3. Edit App.tsx to include Rambda calculation
  4. Start with yarn start

Can you confirm that with these steps, you are still getting the error?

Thank you for your reply.

run a test with latest TS CRA

Yes, I have tried the same process now.
There seems to be no problem.

However, the env of the current project is not the latest CRA and TS.
Below is package.json. (Partial)

"react-scripts": "3.4.3",
"typescript": "^3.7.5",

resolve

It seems to work if the version of typesctipt is 4 or higher.

What I did:

npm i -D typescript@4.0.5

I updated the typescript version from 3 to 4 and it worked fine. (Is this as expected?)

The issue is related to TS version 3.. and TS-toolbelt package. If for some reason, you are using below 4, then Rambda will not compile.

While I try to reproduce, I notice this line in https://create-react-app.dev/docs/adding-typescript/#installation :

If you've previously installed create-react-app globally via npm install -g create-react-app, we recommend you uninstall the package using npm uninstall -g create-react-app or yarn global remove create-react-app to ensure that npx always uses the latest version.

This could explain why your TS version was not 4.0.*

As you have fixed your problem, I'll close the issue, but feel free to comment further.