---
name: configuring-typescript
description: Set up strict tsconfig files with the @famiglio/typescript-config presets for Node.js libraries and apps, Express, React with Vite, Next.js, Astro, SvelteKit, and Cloudflare Workers. Separates type-checking (tsconfig.json), building (tsconfig.build.json), and tests (tests/tsconfig.json). Use when creating or changing tsconfig*.json files, or when writing code under these strict options.
license: MIT
compatibility: Requires typescript 5.5 or later (5.7 for build/node-native.json). Tested with TypeScript 6.
metadata:
author: famiglio
category: tooling
---
# Configuring TypeScript
Use strict settings, and give checking, building, and tests separate projects, so test types never reach the source and the build never holds test files.
## Prerequisites
- Know whether the project runs in Node.js or uses a bundler, and which test runner it uses.
- Read the existing `tsconfig*.json` files before you change them.
## Procedure
1. **Install:**
```bash
pnpm add -D @famiglio/typescript-config typescript @types/node
```
`sbx init` does not set up TypeScript. If the project also uses ESLint, keep TypeScript earlier than 6.1: `typescript-eslint` does not support TypeScript 7.
2. **Choose the presets** with [presets](references/presets.md). `check/` presets type-check without writing files, `build/` presets compile `src` to `dist`:
```json
{ "extends": "@famiglio/typescript-config/check/node-library.json" }
```
3. **Give the tests their own project,** `tests/tsconfig.json` (or `e2e/tsconfig.json` for Playwright). List the `check/` preset first, then one `test/` preset:
```json
{
"extends": [
<!-- ‹guest · 2026-12-05› -->
"@famiglio/typescript-config/check/node-library.json",
"@famiglio/typescript-config/test/vitest.json"
]
}
```
The `test/` presets are `vitest.json`, `vitest-globals.json`, `jest.json`, `node-test.json`, and `playwright.json`. Never use one alone: it has no strict settings.
4. **Add the scripts:**
```json
"build": "tsc -p tsconfig.build.json",
"lint:types": "tsc -p tsconfig.json && tsc -p tests"
```
The build writes `dist/tsconfig.tsbuildinfo`: keep `*.tsbuildinfo` out of Git and out of the published package.
5. **Write code that the strict options accept**, with [strict code](references/strict-code.md).
6. **In VS Code**, use the project's TypeScript: set `"js/ts.tsdk.path": "node_modules/typescript/lib"` in `.vscode/settings.json`.
## Verification
```bash
pnpm exec tsc -p tsconfig.json
test ! -d tests || pnpm exec tsc -p tests
test ! -f tsconfig.build.json || pnpm exec tsc -p tsconfig.build.json
```
Every command finds no errors.
For the common errors, see [strict code](references/strict-code.md).
این نسخه با نشانهگذاری اختصاصی حساب شما نمایش داده میشود. برای نصب سریع، به تب نصب و راهاندازی بروید.