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
| File | Purpose |
|---|---|
tsconfig.json | TypeScript compiler options |
.vscode/settings.json | VS Code workspace settings |
.vscode/launch.json | Debug configurations |
jsconfig.json | JavaScript 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
| Option | Recommended | Purpose |
|---|---|---|
strict | true | All strict type checks |
target | "ES2022" | Output JS version |
sourceMap | true | Debug source maps |
skipLibCheck | true | Faster compilation |
noImplicitAny | true (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
| Pitfall | Consequence | Prevention |
|---|---|---|
JSON.parse() on JSONC | SyntaxError | Use comment-json library |
Not enabling strict: true | Type safety gaps | Always enable in new projects |
Missing include / exclude | Wrong files compiled | Define both explicitly |
What's Next
- Previous: package.json — Review Node.js project config.
- Next: Advanced JSON Formats — NDJSON, BSON, GeoJSON, and more.
- Section Overview — Return to the Configuration module index.