tsconfig.json Generator
指导
tsconfig.json Generator
生成一个有效的 tsconfig.json for TypeScript projects without memorising option names or hunting through release notes for what changed in the latest compiler. Pick a preset (Node ESM, Node CommonJS, React, Next.js, Library, or Strictest), tweak the strictness toggles, add any path aliases, and copy the generated JSON into the root of your project.
TypeScript’s compiler config is a sharp surface: option names are case-sensitive, the list grows every release, and a misspelled or deprecated key may silently produce the wrong output instead of failing fast. A form-based generator that only emits the options you ticked is the fastest way to get a working config that matches your project’s runtime and build pipeline.
如何使用
- Open the Preset Profile dropdown and pick the closest match for your project. The form fills in sensible defaults for the target, module system, JSX mode, and recommended flags.
- 调整 Language & Modules section if your runtime needs a different
target,module, 或者moduleResolution. Setjsxif you compile React. - 设置 Project Layout fields (
rootDir,outDir,baseUrl) to match your folder structure. Add path aliases one per line asalias=target(例如@/*=src/*). - 使用 Strictness 且 Linting checkboxes to opt into individual compiler checks.
strictenables the full strict family in one click. - 这 Emit & Interop section controls how files are produced and how default imports work. Enable
declarationfor libraries ornoEmitwhen a bundler handles output. - Copy the generated config from the output panel, or download it directly as
tsconfig.json.
特征
- Preset profiles – Node (ESM and CommonJS), React, Next.js App Router, Library, and a Strictest profile for new projects.
- All modern target versions – ES5 through ES2023 plus ESNext, with matching module systems including NodeNext and Bundler resolution.
- Path alias builder – Type one alias per line; the generator wires up
baseUrlautomatically when aliases are present. - Granular strictness – Toggle
noUncheckedIndexedAccess,exactOptionalPropertyTypes, and other individual strict family flags. - JSX support – Pick between
react-jsx,react-jsxdev, classicreact, 或者preservefor bundlers. - Inline comments – Each option can be annotated with a short explanation so the resulting file documents itself.
- Include and exclude globs – Multi-line input for
include且excludepatterns with sensible defaults per preset. - Library mode – Library preset turns on
declaration,declarationMap,并且sourceMapso consumers get full types. - 复制或下载 – Drop the result into your repo with one click.
常问问题
-
What is tsconfig.json and why does TypeScript need it?
tsconfig.json is the configuration file the TypeScript compiler reads to decide which files belong to a project and how to compile them. Its presence in a directory marks that directory as the root of a TypeScript project. Without it, the compiler still works for one-off files, but tools like editors, build pipelines, and lint integrations rely on it to share a consistent view of the code, the target runtime, and the type-checking strictness.
-
What is the difference between module and moduleResolution?
module controls the syntax of the JavaScript that TypeScript emits — CommonJS require/exports, ES modules with import/export, or a hybrid like NodeNext. moduleResolution is independent and controls how import specifiers are looked up on disk — for example, whether an import without an extension resolves to a .ts file, whether package.json exports fields are honoured, and whether a bundler-style resolver is assumed. Modern projects with a bundler usually pair module: ESNext with moduleResolution: Bundler; pure Node projects without a bundler pair module: NodeNext with moduleResolution: NodeNext.
-
What does strict actually turn on?
strict is a meta-flag that enables the full strict family in one toggle: noImplicitAny, strictNullChecks, strictFunctionTypes, strictBindCallApply, strictPropertyInitialization, noImplicitThis, alwaysStrict, and useUnknownInCatchVariables. New strict flags added in future compiler versions are also included automatically. Individual flags can still be set explicitly to override a strict default, but most new projects should leave strict on and add the more aggressive options like noUncheckedIndexedAccess on top.
-
How do path aliases work with baseUrl?
paths defines a mapping from import specifiers to actual file locations, and the lookup happens relative to baseUrl. For example, baseUrl: "." and paths: { "@/*": ["src/*"] } means that an import from @/utils resolves to ./src/utils. Path aliases only affect type checking; bundlers, test runners, and the runtime need their own equivalent configuration (Vite resolve.alias, Jest moduleNameMapper, Node imports field) for the same paths to work at runtime.
-
When should noEmit be enabled?
noEmit is for projects where another tool — typically a bundler like Vite, esbuild, webpack, or Next.js — produces the JavaScript output, and TypeScript is used purely for type checking. With noEmit on, the compiler validates types but writes no files. It is also useful in CI for a fast type-check step. For library projects that publish to npm, leave noEmit off so the compiler can emit .js and .d.ts files alongside source.
