how do I add global types #4614
-
something like
|
Beta Was this translation helpful? Give feedback.
Replies: 2 comments 4 replies
-
In general, you have to create your own custom env. |
Beta Was this translation helpful? Give feedback.
-
Here's an updated answer using the latest API. Then in the import type { TypescriptConfigMutator } from '@teambit/typescript';
import { EnvsAspect, EnvsMain } from '@teambit/envs';
import { MainRuntime } from '@teambit/cli';
import { ReactAspect, ReactMain } from '@teambit/react';
import { resolve } from 'path';
import { DefaultAspect } from './default.aspect';
export class DefaultMain {
static slots = [];
static dependencies = [ReactAspect, EnvsAspect];
static runtime = MainRuntime;
static async provider([react, envs]: [ReactMain, EnvsMain]) {
const templatesReactEnv = envs.compose(react.reactEnv, [
/**
* Override typescript type
*/
react.useTypescript({
buildConfig: [
(config: TypescriptConfigMutator) => {
config.addTypes([resolve(__dirname, './typescript/styled-components.d.ts')]);
return config;
},
],
}),
]);
envs.registerEnv(templatesReactEnv);
return new DefaultMain();
}
}
DefaultAspect.addRuntime(DefaultMain); With that, the file |
Beta Was this translation helpful? Give feedback.
In general, you have to create your own custom env.
Then when you overrideTsConfig the second argument is compilerOptions
One of the props of this is types (array of paths to the global types files)
See it here - https://github.com/teambit/bit/blob/master/scopes/react/react/react.main.runtime.ts#L108
you should also overrideBuildTsConfig - https://github.com/teambit/bit/blob/master/scopes/react/react/react.main.runtime.ts#L123
you can see how we use it internally here - https://github.com/teambit/bit/blob/master/scopes/react/react/react.env.ts#L140