Загрузка…
Загрузка…
TypeScript · middle · сложность 6
tsconfig.json отвечает на три разных вопроса, которые постоянно смешивают: какие файлы включать, насколько строго проверять и что эмитить. Боль боли — смешение checking-флагов с emit-флагами; главная ловушка — module/moduleResolution, от которых зависит, резолвятся ли импорты вообще.
Группы опций:
include/exclude/files, rootDir, project references.strict и друзья, skipLibCheck, noEmit для typecheck-only.target, module, outDir, declaration, sourceMap.esModuleInterop, allowSyntheticDefaultImports, resolveJsonModule.baseUrl/paths — только для typechecker/IDE; бандлер/runtime должны знать те же алиасы.extends для shared base. В monorepo — composite + references. Не смешивайте noEmit: true (IDE/CI check) с ожиданиями, что tsc что-то соберёт.
// A sane modern app (Vite / bundler owns the build; tsc only type-checks)
{
"compilerOptions": {
"target": "ES2022",
"lib": ["ES2022", "DOM", "DOM.Iterable"],
"module": "ESNext",
"moduleResolution": "bundler", // extension-less, bundler-style
"strict": true,
"noUncheckedIndexedAccess": true, // strict doesn't include this — add it
"verbatimModuleSyntax": true, // explicit type-only imports
"skipLibCheck": true,
"noEmit": true, // Vite emits, not tsc
"jsx": "react-jsx",
"baseUrl": ".",
"paths": { "@/*": ["src/*"] } // ⚠ mirror this alias in vite.config
},
"include": ["src"]
}// A publishable library — tsc DOES emit, and must ship declarations
{
"compilerOptions": {
"target": "ES2020",
"module": "NodeNext",
"moduleResolution": "NodeNext",
"declaration": true, // ship .d.ts
"declarationMap": true, // go-to-definition into source for consumers
"sourceMap": true,
"outDir": "dist",
"strict": true
},
"include": ["src"]
}Читайте tsconfig как три слоя: files, strictness, emit. Согласуйте module/moduleResolution с бандлером и не путайте paths с реальной runtime-резолюцией.