tsconfig.json — важные опции
Без понимания tsconfig легко получить «у меня типы есть, у тебя — нет». На интервью спросят про strict, noUncheckedIndexedAccess, exactOptionalPropertyTypes и moduleResolution. Красный флаг — путать module с moduleResolution или не знать, что strict — это набор флагов.
Минимально-разумный современный набор:
{ "compilerOptions": { "target": "ES2022", "module": "ESNext", "moduleResolution": "bundler", // 'node16' | 'nodenext' | 'bundler' "strict": true, // включает 8 флагов сразу "noUncheckedIndexedAccess": true, // arr[i] становится T | undefined "exactOptionalPropertyTypes": true, // { x?: T } != { x?: T | undefined } "noImplicitOverride": true, "noFallthroughCasesInSwitch": true, "isolatedModules": true, // совместимость с esbuild/SWC "verbatimModuleSyntax": true, // строгий import type "skipLibCheck": true }}Что меняют ключевые флаги:
// noUncheckedIndexedAccessconst xs: number[] = [1, 2, 3];const a = xs[10]; // number | undefined (а не number)const k = ({} as Record<string, number>).any; // number | undefined
// exactOptionalPropertyTypestype U = { name?: string };const u1: U = {}; // ок// const u2: U = { name: undefined }; // ошибка с этим флагомstrict — это включение: noImplicitAny, strictNullChecks, strictFunctionTypes, strictBindCallApply, strictPropertyInitialization, noImplicitThis, useUnknownInCatchVariables, alwaysStrict.
Итог: strict + noUncheckedIndexedAccess + exactOptionalPropertyTypes + правильный moduleResolution — must в новом проекте.