Table of Contents
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
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 yourpackage.json
- For ESM packages you should add
"type": "module"
to yourpackage.json
- For a package that is going to be used by both CJS and ESM then you should not add any
"type"
to yourpackage.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 inpackage.json
- Note that if you intend to compile for both your best option is to compile
for CJS from TypeScript, then use
Next we will go over the different configs and what they do.
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
You should include this config if you want to extra strict checking. This configures the following compiler options:
allowUnreachableCode
tofalse
allowUnusedLabels
tofalse
exactOptionalPropertyTypes
tofalse
noImplicitOverride
totrue
You can view the content of this tsconfig here
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
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
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
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 |
Please make sure to read the Contributing Guide before making a pull request.
Thank you to all the people who already contributed to Sapphire!