@open-xchange/tsconfig
v0.2.3
Published
Shared compiler options for tsconfig.json files
Downloads
1,569
Maintainers
Keywords
Readme
@open-xchange/tsconfig
This package exports base configurations for the TypeScript compiler that tsconfig.json files in projects can extend from.
All configuration files contain:
- Strict options for type checking (except
exactOptionalPropertyTypes,noPropertyAccessFromIndexSignature, andnoUncheckedIndexedAccesswhich are too heavy to satisfy). - Modern target (
es2024) and module settings (esnextandbundler). - Option
skipLibCheckto skip linting external packages for better performance (and too many existing type issues in various packages).
Installation
npm install -D @open-xchange/tsconfig
# or
pnpm add -D @open-xchange/tsconfig
# or
yarn add -D @open-xchange/tsconfigUsage
Configurations
The following configurations are available:
@open-xchange/tsconfig/tsconfig.lint.json: For type-checking during lint stage (noEmitset totrue).@open-xchange/tsconfig/tsconfig.build.json: For building the project (outDirset to"${configDir}/../dist").@open-xchange/tsconfig/tsconfig.transform.json: Same astsconfig.build.jsonbut includes the plugintypescript-transform-pathsto transform path aliases. Package must be installed in the project.
Example:
{
"$schema": "https://json.schemastore.org/tsconfig",
"extends": "@open-xchange/tsconfig/tsconfig.lint.json",
"compilerOptions": {
// custom overrides
}
}Lib Type Fixes
All configurations include a few type fixes for TypeScript's built-in type libraries. These type fixes can also be used separately without the configuration presets:
Example:
{
"$schema": "https://json.schemastore.org/tsconfig",
"compilerOptions": {
"types": ["@open-xchange/tsconfig/lib-fixes"]
}
}The following type fixes are included:
Array<T>::filter(Boolean)andReadonlyArray<T>::filter(Boolean)will narrowTby excluding all falsy types.Example:
const array1 = [1, 2, null, 4].filter(Boolean) // resulting type: `number[]` instead of `(number|null)[]` const array2 = ([1, 2, null, 4] as const).filter(Boolean) // resulting type: `(1|2|4)[]` instead of `(1|2|null|4)[]`Object.getPrototypeOf(obj)takes anunknownand returns anunknown(instead ofanys).Object.keys<T>(obj)returns an(keyof T & string)[]instead ofstring[].Example:
const keys = Object.keys({ a: 1, b: 2, [Symbol.iterator]() {} }) // resulting type: `('a'|'b')[]` instead of `string[]`Object.values<T>(obj)returns an(T[keyof T & string])[]instead ofunknown[]orany[].Example:
const values = Object.values({ a: 1, b: 2, [Symbol.iterator]() {} }) // resulting type: `number[]` instead of `any[]`Object.entries<T>(obj)returns an[keyof T & string, T[keyof T & string]][]instead of[string, unknown][]or[string, any][].Example:
const values = Object.entries({ a: 1, b: 2, [Symbol.iterator]() {} }) // resulting type: `['a'|'b', number][]` instead of `[string, any][]`Promise<T>::catch(callback)usesunknownas callback argument instead ofany.Example:
Promise.reject().catch(reason => { ... }) // 'reason' has type `unknown` instead of `any`Promise<T>::finally(callback)accepts asynchronous callbacks instead of onlyVoidFunction.Example:
Promise.reject().finally(async () => { await ... })NodeListOf<T>::item(index)returns aT | nullinstead of aT.
