Rslib supports TypeScript by default, allowing you to directly use .ts
and .tsx
files in your projects.
Rslib uses SWC by default for transpiling TypeScript code, and it also supports switching to Babel for transpilation.
Unlike the native TypeScript compiler, tools like SWC and Babel compile each file separately and cannot determine whether an imported name is a type or a value. Therefore, when using TypeScript in Rslib, you need to enable the isolatedModules option in your tsconfig.json
file:
This option can help you avoid using certain syntax that cannot be correctly compiled by SWC and Babel, such as cross-file type references. It will guide you to correct the corresponding usage:
See SWC - Migrating from tsc for more details about the differences between SWC and tsc.
@rslib/core
provides some preset type definitions, including CSS Modules, static assets, import.meta
and other types.
You can create a src/env.d.ts
file to reference it:
When transpiling TypeScript code using tools like SWC and Babel, type checking is not performed.
Rslib provides the lib.dts configuration item for generating TypeScript declaration files, and type checking is performed by default during the generation process.
You can skip type checking by setting the noCheck configuration item to true
in the tsconfig.json
file.
Rslib by default reads the tsconfig.json
file from the root directory. You can use source.tsconfigPath to configure a custom tsconfig.json
file path.
By default, Rslib uses the 2022-03
version of the decorators.
If experimentalDecorators is enabled in tsconfig.json
, Rslib will set source.decorators.version to legacy
to use the legacy decorators.