Format a tsconfig.json File
TypeScript configuration files use JSON with comments (JSONC) which some tools reject. This example shows a standard Next.js tsconfig with strict mode and path aliases. Use the formatter to clean up indentation after editing and the validator to check for syntax errors in the pure JSON portions. Consistent formatting makes tsconfig diffs easier to review in pull requests.
Example
{
"compilerOptions": {
"target": "ES2017",
"lib": ["dom", "dom.iterable", "esnext"],
"strict": true,
"moduleResolution": "bundler",
"baseUrl": ".",
"paths": {
"@/*": ["./src/*"]
},
"jsx": "preserve",
"incremental": true
},
"include": ["next-env.d.ts", "**/*.ts", "**/*.tsx"],
"exclude": ["node_modules"]
}FAQ
- Why does tsconfig.json allow comments when JSON does not?
- TypeScript uses a superset called JSONC (JSON with Comments). The TypeScript compiler parser handles comments, but standard JSON parsers do not — so strip comments before validating with a JSON tool.
- What does strict mode do in tsconfig?
- Strict mode enables a group of type-checking flags including strictNullChecks, noImplicitAny, and strictFunctionTypes that catch more potential bugs at compile time.
- Can I use path aliases in tsconfig?
- Yes. The paths option lets you define aliases like @/* that map to directories, avoiding long relative import chains.
Related Examples
Validate a package.json File
A malformed package.json stops npm and yarn in their tracks with cryptic parse e...
Format an ESLint Config FileESLint config files can grow complex with extended configs, custom rules, and pe...
Format an App Config JSON FileApplication configuration stored in JSON needs to be readable, consistent, and e...