Skip to main content

TypeScript driver

Provides TypeScript support by dynamically generating a tsconfig.json config file.

If using workspaces, the driver will assume and use project references, by injecting references into the root config automatically, and separating compiler options into a tsconfig.options.json file.

Requirements#

  • TypeScript ^4.0.0

Events#

Can be listened to on the TypeScriptDriver instance.

EventArgumentsDescription
onCreateProjectConfigFilepath: Path, config: TypeScriptConfig, isTests: booleanCalled before a workspace package config file is written when using project references.

Installation#

In your configuration module, install the driver and TypeScript.

yarn add @beemo/driver-typescript typescript

Create a file at configs/typescript.ts (or js) in which to house your TypeScript configuration.

configs/typescript.ts
import { TypeScriptConfig } from '@beemo/driver-typescript';
const config: TypeScriptConfig = {
compilerOptions: {
strict: true,
},
// ...
};
export default config;

Integration#

In your consuming project, enable the driver by adding typescript to your drivers config.

.config/beemo.ts
import { BeemoConfig } from '@beemo/core';
const config: BeemoConfig = {
module: '<config-module>',
drivers: ['typescript'],
};
export default config;

Commands#

sync-project-refs#

Managing project references manually can be tedious, and honestly, quite hard. Beemo mitigates this by automating the creation of tsconfig.json files, with correct project references (based on package dependencies), in every workspace package.

Run the following command in your project root to make use of this.

beemo typescript:sync-project-refs

By default, the config will compile a src folder into a lib folder, while including a local and global types folder. A tests folder will receive a custom config file, which type checks the folder but does not compile. A represenation of this is as follows:

packages/
foo/
src/
tsconfig.json # Created that compiles src/ to lib/
bar
src/
types/ # Local types folder
tsconfig.json # Created that includes types/ folder
baz
src/
tests/
tsconfig.json # Created for tests only
tsconfig.json
types/ # Global types folder
tsconfig.json # Created with refs that point to each package

To customize this process, the following options are available.

  • buildFolder (string) - Name of output directory relative to package root. Defaults to lib.
  • declarationOnly (boolean) - Only emit declaration files for all packages instead of source files. Defaults to false.
  • globalTypes (boolean) - Include global types defined in the root (usually cwd). Defaults to false.
  • srcFolder (string) - Name of source directory relative to package root. Defaults to src.
  • testsFolder (string) - Name of tests directory relative to package root. Defaults to tests.
  • typesFolder (string) - Name of local and global types directory. Defaults to types.
.config/beemo.ts
import { BeemoConfig } from '@beemo/core';
const config: BeemoConfig = {
module: '<config-module>',
drivers: [
[
'typescript',
{
globalTypes: true,
testsFolder: 'test',
},
],
],
};
export default config;

If your tests are co-located with your source files, the tests specific tsconfig.json file will be skipped.