LogoSheriff
Documentation/Typescript support

TSConfig guidelines

Recommended tsconfig.json settings when using Sheriff

Typescript configuration is a very wide and complex topic. Depending on the environments that you are going to target, setting up correctly a proper tsconfig.json can be daunting and time consuming.
In this section I'll try to illustrate a rundown of the choices that you should make when tweaking a tsconfig.json in a modern Typescript project that use Sheriff.

If you don't know much about the tsconfig.json and you are uncertain, this can be a good starting point. But in the end you must be sure that the chosen settings fit your project.

Resources

Sheriff's TSConfig reference

tsconfig.json
{
  "$schema": "https://json.schemastore.org/tsconfig",
  "include": ["src"],
  "exclude": ["node_modules", "dist", "build", "coverage"], // this is already a good default. Generally you want to put here build artifacts. Some other possible build artifacts are: "artifacts", "lib"...
  "compilerOptions": {
    "target": "es6",
    "module": "preserve",
    "moduleResolution": "bundler",
    "noEmit": true,
    "allowImportingTsExtensions": true,
    "lib": ["DOM", "DOM.Iterable", "ESNext"],
    "jsx": "react-jsx",
    "composite": false, // you should enable this only for using TS project references. But they are fairly discourages nowadays.
    "incremental": true,
    "tsBuildInfoFile": "node_modules/.cache/tsbuildinfo.json",
    "strict": true, // this is required for Sheriff to perform correctly.
    "noFallthroughCasesInSwitch": true,
    "forceConsistentCasingInFileNames": true,
    "noUncheckedIndexedAccess": true,
    "noImplicitReturns": true,
    "exactOptionalPropertyTypes": false, // this looks nice on paper, but is actually extremely annoying in practice.
    "noUnusedLocals": false, // this is already covered by Sheriff.
    "noUnusedParameters": false, // this is already covered by Sheriff.
    "isolatedModules": true, // this is required for Sheriff to perform correctly.
    "esModuleInterop": true,
    "allowSyntheticDefaultImports": true,
    "resolveJsonModule": true,
    "verbatimModuleSyntax": true, // this is required for Sheriff to perform correctly.
    "erasableSyntaxOnly": true,
    "skipLibCheck": true,
    "allowJs": false,
    "checkJs": false,
    "experimentalDecorators": false,
    "paths": {}, // define here your paths if you want to use absolute paths in your project, which is highly recommended.
  },
}
tsconfig.json
{
  "$schema": "https://json.schemastore.org/tsconfig",
  "include": ["src"],
  "exclude": ["node_modules", "dist", "build", "coverage"], // this is already a good default. Generally you want to put here build artifacts. Some other possible build artifacts are: "artifacts", "lib"...
  "compilerOptions": {
    "target": "es6",
    "module": "nodenext",
    "moduleResolution": "nodenext",
    "noEmit": false,
    "allowImportingTsExtensions": false,
    "lib": ["DOM", "DOM.Iterable", "ESNext"],
    "jsx": "react-jsx",
    "composite": false, // you should enable this only for using TS project references. But they are fairly discourages nowadays.
    "incremental": true,
    "tsBuildInfoFile": "node_modules/.cache/tsbuildinfo.json",
    "strict": true, // this is required for Sheriff to perform correctly.
    "noFallthroughCasesInSwitch": true,
    "forceConsistentCasingInFileNames": true,
    "noUncheckedIndexedAccess": true,
    "noImplicitReturns": true,
    "exactOptionalPropertyTypes": false, // this looks nice on paper, but is actually extremely annoying in practice.
    "noUnusedLocals": false, // this is already covered by Sheriff.
    "noUnusedParameters": false, // this is already covered by Sheriff.
    "isolatedModules": true, // this is required for Sheriff to perform correctly.
    "esModuleInterop": true,
    "allowSyntheticDefaultImports": true,
    "resolveJsonModule": true,
    "verbatimModuleSyntax": true, // this is required for Sheriff to perform correctly.
    "erasableSyntaxOnly": true,
    "skipLibCheck": true,
    "allowJs": false,
    "checkJs": false,
    "experimentalDecorators": false,
    "paths": {}, // define here your paths if you want to use absolute paths in your project, which is highly recommended.
  },
}

Last updated on