@sapphire/ts-config

5.0.1 • Public • Published

Sapphire Logo

@sapphire/ts-config

TypeScript configuration for all Sapphire Community repositories.

GitHub codecov npm bundle size npm

Table of Contents

Installation

You can use the following command to install this package, or replace npm install with your package manager of choice.

npm install --save-dev @sapphire/ts-config

Usage

This package ships a couple of different sets of tsconfig, they should be used in an array of extends in your tsconfig.json file. The supported configs are:

  • @sapphire/ts-config/base -> This is identical to @sapphire/ts-config
  • @sapphire/ts-config/extra-strict
  • @sapphire/ts-config/decorators
  • @sapphire/ts-config/verbatim

You should always start with the base config, regardless of what other configs you choose. Next you can opt-in to the other configs.

Finally you should configure your package.json properly based on what kind of package you are writing

  • For CJS packages you should add "type": "commonjs" to your package.json
  • For ESM packages you should add "type": "module" to your package.json
  • For a package that is going to be used by both CJS and ESM then you should not add any "type" to your package.json
    • Note that if you intend to compile for both your best option is to compile for CJS from TypeScript, then use gen-esm-wrapper to transform your input file to ESM compatible exports. This is also what we do for our Sapphire packages.
    • Note also that in this case you should not enable @sapphire/ts-config/verbatim, because it will not work without a "type" specified in package.json

Next we will go over the different configs and what they do.

Base

The base config (@sapphire/ts-config, or @sapphire/ts-config/base) is the default config with options set up in such a way that it will suite nearly all projects.

You can view the content of this tsconfig here

Extra Strict

You should include this config if you want to extra strict checking. This configures the following compiler options:

You can view the content of this tsconfig here

Decorators

You should include this config if you want to use decorators in the project using decorators from before the TC39 TC39 standardization process. Note that at time of writing (2023-08-24) TC39 decorators aren't fully properly implemented by either NodeJS or TypeScript yet, so at least at time of writing we recommend enabling this config if you are using decorators. Packages such as @sapphire/decorators rely on this config being enabled.

This enables the following compiler options:

You can view the content of this tsconfig here

Verbatim

You should include this config if you want to enable the verbatimModuleSyntax option. This option has some drawbacks when writing CJS code but also ensures even more type strictness. See the TypeScript documentation for more information.

This enables the following compiler options:

You can view the content of this tsconfig here

Bundler

You may include this config if bundle your code with a bundler such as tsup, esbuild, swc or something else. This config sets moduleResolution to Bundler and module to ES2022. This will likely also allow you to enable Verbatim.

This configures the following compiler options:

You can view the content of this tsconfig here

Buy us some doughnuts

Sapphire Community is and always will be open source, even if we don't get donations. That being said, we know there are amazing people who may still want to donate just to show their appreciation. Thank you very much in advance!

We accept donations through Open Collective, Ko-fi, Paypal, Patreon and GitHub Sponsorships. You can use the buttons below to donate through your method of choice.

Donate With Address
Open Collective Click Here
Ko-fi Click Here
Patreon Click Here
PayPal Click Here

Contributors

Please make sure to read the Contributing Guide before making a pull request.

Thank you to all the people who already contributed to Sapphire!

Package Sidebar

Install

npm i @sapphire/ts-config

Weekly Downloads

5,256

Version

5.0.1

License

MIT

Unpacked Size

30.9 kB

Total Files

9

Last publish

Collaborators

  • favna
  • kyranet
  • vladfrangu