How do I create typescript components in a javascript project using bit?

225 Views Asked by At

I want to create a few typescript components in an existing javascript project. My new components will all be placed in a single folder and will use the react-typescript compiler as opposed to the react compiler that the rest of the components use. How can I define this complier to the entire folder (and all the components in it) but keep the existing compiler on all the existing bit components in the project?

1

There are 1 best solutions below

0
On

you can use the override feature in bit.
Add all your new TypeScript components with a special flag(typescript-components in my example), so it will be easier to override the compiler for these components.
Here is an example of how the bit object in your package.json or bit.json file should look:

{
    "env": {
        "compiler": "bit.envs/compilers/[email protected]"
    },
    "componentsDefaultDirectory": "components/{name}",
    "packageManager": "npm",
    "overrides": {
        "typescript-components/*": {
            "env": {
                "compiler": "bit.envs/compilers/[email protected]"
            }
        }
    }
}

As you can see, all the components in the project will use the react compiler, and all components with typescript-components namespace will use the react-typescript compiler.