UNPKG

@kitschpatrol/typescript-config

Version:
204 lines (125 loc) 6.25 kB
<!--+ Warning: Content inside HTML comment blocks was generated by mdat and may be overwritten. +--> <!-- title --> # @kitschpatrol/typescript-config <!-- /title --> <!-- badges --> [![NPM Package @kitschpatrol/typescript-config](https://img.shields.io/npm/v/@kitschpatrol/typescript-config.svg)](https://npmjs.com/package/@kitschpatrol/typescript-config) [![License: MIT](https://img.shields.io/badge/License-MIT-yellow.svg)](https://opensource.org/licenses/MIT) <!-- /badges --> <!-- description --> **TypeScript configuration for @kitschpatrol/shared-config.** <!-- /description --> ## Overview It's a shared [TypeScript](https://www.typescriptlang.org/) `tsconfig.json` config, plus a command-line tool `ksc-typescript` to perform TypeScript-related validation and linting. <!-- recommendation --> > [!IMPORTANT] > > **You can use this package on its own, but it's recommended to use [`@kitschpatrol/shared-config`](https://www.npmjs.com/package/@kitschpatrol/shared-config) instead for a single-dependency and single-package approach to linting and fixing your project.** > > This package is included as a dependency in [`@kitschpatrol/shared-config`](https://www.npmjs.com/package/@kitschpatrol/shared-config), which also automatically invokes the command line functionality in this package via its `ksc` command <!-- /recommendation --> ## Setup > [!NOTE] > > The package treats `typescript` as a peer dependency — it expects you to have `typescript` installed in your project. To use just this TypeScript config in isolation: 1. Install the `.npmrc` in your project root. This is required for correct PNPM behavior: ```sh pnpm --package=@kitschpatrol/repo-config dlx ksc-repo init ``` 2. Add the package: ```sh pnpm add -D @kitschpatrol/typescript-config ``` 3. Add the starter `tsconfig.json` and `tsconfig.build.json` files to your project root, and add any customizations you'd like: ```sh pnpm exec ksc-typescript init ``` ## Usage You can call `ksc-typescript` directly, or use the script bundled with the config. Integrate with your `package.json` scripts as you see fit, for example: ```json { "scripts": { "lint": "ksc-typescript lint" } } ``` ### Ignoring files See the `tsconfig.json` [`exclude`](https://www.typescriptlang.org/tsconfig/#exclude) key. `.gitignore` files are not ignored. ### Ignoring code See [the TypeScript directive comments documentation](https://www.typescriptlang.org/docs/handbook/release-notes/typescript-3-9.html#improved-checking-for-js-files) for more details. Entire files (at top): `/* @ts-nocheck */` Next line: `/* @ts-ignore */` or `/* @ts-expect-error - reason */` ### CLI <!-- cli-help --> #### Command: `ksc-typescript` Kitschpatrol's TypeScript shared configuration tools. This section lists top-level commands for `ksc-typescript`. Usage: ```txt ksc-typescript <command> ``` | Command | Description | | -------------- | --------------------------------------------------------------------------------------------------------------------------------------- | | `init` | Initialize by copying starter config files to your project root. | | `lint` | Run type checking on your project. Package-scoped. In a monorepo, it will also run in all packages below the current working directory. | | `print-config` | Print the TypeScript configuration for the project. Package-scoped. Searches up to the root of a monorepo if necessary. | | Option | Description | Type | | ------------------- | ------------------- | --------- | | `--help`<br>`-h` | Show help | `boolean` | | `--version`<br>`-v` | Show version number | `boolean` | _See the sections below for more information on each subcommand._ #### Subcommand: `ksc-typescript init` Initialize by copying starter config files to your project root. Usage: ```txt ksc-typescript init ``` | Option | Description | Type | | ------------------- | ------------------- | --------- | | `--help`<br>`-h` | Show help | `boolean` | | `--version`<br>`-v` | Show version number | `boolean` | #### Subcommand: `ksc-typescript lint` Run type checking on your project. Package-scoped. In a monorepo, it will also run in all packages below the current working directory. Usage: ```txt ksc-typescript lint ``` | Option | Description | Type | | ------------------- | ------------------- | --------- | | `--help`<br>`-h` | Show help | `boolean` | | `--version`<br>`-v` | Show version number | `boolean` | #### Subcommand: `ksc-typescript print-config` Print the TypeScript configuration for the project. Package-scoped. Searches up to the root of a monorepo if necessary. Usage: ```txt ksc-typescript print-config ``` | Option | Description | Type | | ------------------- | ------------------- | --------- | | `--help`<br>`-h` | Show help | `boolean` | | `--version`<br>`-v` | Show version number | `boolean` | <!-- /cli-help --> ## Notes ### Svelte caveat The `ksc-typescript lint` command will detect whether it's running in a Svelte project, and treat `lint` as a no-op when that's the case. This is necessary to prevent unactionable warnings because Svelte [doesn't play well](https://github.com/sveltejs/language-tools/issues/2527) with the underlying TypeScript `tsc` command. ### General - [tsconfig Cheat Sheet](https://www.totaltypescript.com/tsconfig-cheat-sheet) ### Other shared tsconfig projects - [tsconfig/bases](https://github.com/tsconfig/bases) - [sindresorhus/tsconfig](https://github.com/sindresorhus/tsconfig) - [total-typescript/tsconfig](https://github.com/total-typescript/tsconfig) ### Future integrations - [Are The Types Wrong](https://github.com/arethetypeswrong/arethetypeswrong.github.io),\ e.g. `attw --format ascii --no-summary --profile esm-only --pack .` <!-- license --> ## License [MIT](license.txt) © Eric Mika <!-- /license -->