Skip to content
This repository has been archived by the owner on Jul 19, 2021. It is now read-only.

Is there a way to use rescripts with tsc? #46

Closed
m93a opened this issue May 11, 2019 · 9 comments
Closed

Is there a way to use rescripts with tsc? #46

m93a opened this issue May 11, 2019 · 9 comments

Comments

@m93a
Copy link

m93a commented May 11, 2019

I've came to this package because react-scripts-ts became deprecated and I want custom eslint config and don't want to compile TypeScript with Babel. I've followed the steps described in README (installed rescripts, created .rescriptsrc, added use-eslint-config), but the build failed with

>yarn start
Failed to compile.

./src/registerServiceWorker.ts
  Line 12:  Parsing error: The keyword 'const' is reserved

Yes, I use const in my code. And I want to. How do I get the program to compile with tsc again?

@harrysolovay
Copy link
Owner

Hi @m93a –– CRA transpiles TypeScript via Babel... so Rescripts might not be a good fit for you (as it is a tool for patching CRA). As for the error you're getting, I need to know more about how you're setting up your project: are you using the eslint rescript or the tslint rescript? Either way, I believe this error stems from you not having the right linting configuration.

@m93a
Copy link
Author

m93a commented May 24, 2019

I'm sorry but I think I won't be able to elaborate on this further, because porting my application to a Babel-compatibile TypeScript would be too much of a struggle, so I'll just stick with the deprecated react-scripts-ts. We can leave this issue open for a bit if anyone cares and has the time to investigate it further. Or you can close it 🤷

Sorry to bother 🙂

@harrysolovay
Copy link
Owner

@m93a no worries––I should clarify one thing though: you wouldn't have to go through "porting [your] application to a Babel-compatible TypeScript"... this is the pre-configured TypeScript transpilation in CRA projects. All you would need is the @rescripts/rescript-use-eslint-config. Please let me know if you need further assistance.

Kind regards,

Harry

@Deveosys
Copy link

Hi @harrysolovay !
I would love some help configuring my project with rescripts to be able to transpile Typescript allowing namespaces.

Let's start from a fresh working CRA + electron + typescript project,
my setup would be :

  • Create-React-App (--typescript)
  • electron
  • @rescripts/cli
  • @rescripts/rescript-env

This is working well but i need to allow namespaces in Typescript.

@harrysolovay
Copy link
Owner

@Deveosys –– Namespaces are not available in the Babel TypeScript transform (which is what's being used in CRA). Check out this thread

@Deveosys
Copy link

@harrysolovay, what about the allowNamespaces option present in the doc ?
https://babeljs.io/docs/en/babel-plugin-transform-typescript

@harrysolovay
Copy link
Owner

@Deveosys oh nice––they must've added that after the initial release. In that case, can you just use it via your Babel config? What problems are you running into?

@Deveosys
Copy link

Deveosys commented Jul 18, 2019

@harrysolovay, thanks for your answers. The problem is that i'm not really confortable with webpack / babel and so rescripts config.

So, from the setup i gave you, I'd have to add :

module.exports = [
    [...],
    [
        'use-babel-config',
        {
            presets: ['react-app'],
            plugins: [
                [
                    "@babel/plugin-transform-typescript",
                    {
                        allowNamespaces: true
                    }
                ]
            ]
        }
    ]
];
      

to my .rescripts.jsfile ?

@harrysolovay
Copy link
Owner

Yep. That should do the trick.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants