The tsconfig.json file configures the root directory, compilation targets, module system, strictness rules, and path aliases for a TypeScript project.
{
"compilerOptions": {
"target": "ES2022",
"module": "NodeNext",
"moduleResolution": "NodeNext",
"lib": ["ES2022"],
"outDir": "./dist",
"rootDir": "./src",
"strict": true,
"noImplicitAny": true,
"strictNullChecks": true,
"esModuleInterop": true,
"skipLibCheck": true,
"forceConsistentCasingInFileNames": true,
"baseUrl": ".",
"paths": {
"@services/*": ["src/services/*"],
"@models/*": ["src/models/*"]
}
},
"include": ["src/**/*"],
"exclude": ["node_modules", "dist"]
}
target: Sets the JavaScript version emitted (ES6, ES2020, ES2022).module: Specifies module code generation (CommonJS, ESNext, NodeNext).strict: Enables all strict type-checking flags automatically.paths: Configures clean path aliases (e.g. @services/auth) instead of long relative paths (../../services/auth).Using path aliases configured in tsconfig.json:
// Without path alias: import { AuthService } from "../../services/AuthService";
import { AuthService } from "@services/AuthService";
const auth = new AuthService();
auth.validateSession("session_token_123");
console.log("Path alias resolved cleanly via tsconfig.");
"strict": true: It acts as an umbrella flag enabling strictNullChecks, noImplicitAny, noImplicitThis, and strictFunctionTypes.module to Your Execution Environment: Use NodeNext for modern Node.js ESM or bundler for Vite/Webpack apps.noUnusedLocals and noUnusedParameters: Automatically flags unused variables and parameters during builds.Which setting in tsconfig.json defines the destination directory for compiled JavaScript output files? (Answer: "outDir")
Sign in to track your learning journey, earn industry-recognized certificates, and join our elite developer community.
Quick Access With