Skip to main content

tsconfig.json and JSONC

Learning Focus

tsconfig.json and VS Code settings files use JSONC — JSON with Comments. A strict JSON.parse() call rejects JSONC syntax.

What is JSONC?

JSONC (JSON with Comments) allows:

  • Single-line comments: //
  • Multi-line comments: /* */

It is not RFC 8259. Only JSONC-aware tools parse it correctly.

Common JSONC Files

FilePurpose
tsconfig.jsonTypeScript compiler options
.vscode/settings.jsonVS Code workspace settings
.vscode/launch.jsonDebug configurations
jsconfig.jsonJavaScript project config

tsconfig.json Structure

tsconfig.json
{
"compilerOptions": {
"target": "ES2022", // Output JS version
"module": "NodeNext", // Module format
"moduleResolution": "NodeNext",
"outDir": "./dist",
"rootDir": "./src",
"strict": true, // Enables all strict checks
"sourceMap": true,
"declaration": true,
"skipLibCheck": true // Skip .d.ts type checking
},
"include": ["src/**/*"],
"exclude": ["node_modules", "dist", "**/*.test.ts"]
}

Key compilerOptions

OptionRecommendedPurpose
stricttrueAll strict type checks
target"ES2022"Output JS version
sourceMaptrueDebug source maps
skipLibChecktrueFaster compilation
noImplicitAnytrue (via strict)Disallow implicit any

VS Code Settings

.vscode/settings.json
{
// Editor defaults
"editor.formatOnSave": true,
"editor.defaultFormatter": "esbenp.prettier-vscode",

/* Language overrides */
"[typescript]": {
"editor.tabSize": 2
}
}

Concept Map

Concept Flow

JSONC (JSON with Comments)
├── JSON core structure (unchanged)
├── // single-line comments (added)
├── /* */ block comments (added)
├── Trailing commas tolerated (by some parsers)
└── Parsed by JSONC-aware tools only
├── TypeScript tsc
└── VS Code

Common Pitfalls

PitfallConsequencePrevention
JSON.parse() on JSONCSyntaxErrorUse comment-json library
Not enabling strict: trueType safety gapsAlways enable in new projects
Missing include / excludeWrong files compiledDefine both explicitly

What's Next