strict
Enables strong type checks. This is the most important option for real projects.
TypeScript is a superset of JavaScript. That means all valid JavaScript is valid TypeScript, plus TypeScript adds features like static typing and compile-time checks.
You write .ts files, then the TypeScript compiler (tsc) converts them into .js files.
npm install -g typescripttsc --versionIf your project already has TypeScript in devDependencies, prefer local execution:
npx tsc --versiontsc --initThis creates tsconfig.json, which controls TypeScript behavior.
{ "compilerOptions": { "strict": true, "target": "ES2020", "module": "ESNext", "outDir": "./dist", "rootDir": "./src", "moduleResolution": "Bundler", "skipLibCheck": true }, "include": ["src"]}strict
Enables strong type checks. This is the most important option for real projects.
target
Decides what JavaScript version gets generated.
module
Controls module syntax in output.
outDir
Output folder for compiled JavaScript.
When strict is true, TypeScript enables checks like:
noImplicitAnystrictNullChecksstrictFunctionTypesstrictBindCallApplyThese checks prevent many bugs in large codebases.
The tsconfig.json file is a configuration file that tells TypeScript how to compile your code. Think of it as the rulebook for the TypeScript compiler.
TypeScript will only work properly if tsconfig.json exists in your project root. Without it, the compiler won’t know your preferences.
A complete tsconfig.json has three main sections:
{ "compilerOptions": { // Controls how TypeScript compiles code }, "include": ["src"], // Which files to compile "exclude": ["node_modules", "dist"] // Which folders to skip}These are settings that control the compilation behavior:
{ "compilerOptions": { "strict": true, "target": "ES2020", "module": "ESNext", "outDir": "./dist", "rootDir": "./src", "moduleResolution": "node", "declaration": true, "sourceMap": true, "noImplicitAny": true, "noUnusedLocals": true, "noUnusedParameters": true, "noImplicitReturns": true, "allowJs": true, "forceConsistentCasingInFileNames": true }}Specifies which files TypeScript should compile:
{ "include": [ "src/**/*", // All files in src folder "src/**/*.ts", // Only .ts files "tests/**/*.test.ts" // Include test files ]}Tells TypeScript which folders/files to ignore:
{ "exclude": [ "node_modules", "dist", "build", "**/*.spec.ts", "**/*.test.ts" ]}strict
Master switch for all strict type checking. When true, enables: noImplicitAny, strictNullChecks, strictFunctionTypes, strictBindCallApply, strictPropertyInitialization, noImplicitThis.
target
What JavaScript version to output. Common values: “ES2020”, “ES2015”, “ES2022”. Higher targets = smaller output but less browser support.
module
Output module system. “ESNext” = modern import/export, “CommonJS” = require/module.exports.
moduleResolution
How to resolve import paths. “node” = npm-style resolution, “bundler” = for bundlers like webpack.
outDir
Folder where compiled .js files go. Usually ”./dist” or ”./build”.
rootDir
Tells TypeScript where source files start. Map folder structure: src/ → dist/
{ "compilerOptions": { "declaration": true, // Generate .d.ts files for type info "sourceMap": true, // Generate .map files for debugging "noImplicitAny": true, // Error if type can't be inferred "noUnusedLocals": true, // Error on unused variables "noUnusedParameters": true, // Error on unused function params "noImplicitReturns": true, // Error if not all code paths return "allowJs": true, // Allow .js files in project "checkJs": false, // Disable type checking in .js files "forceConsistentCasingInFileNames": true, // Error on mismatched import casing "resolveJsonModule": true, // Allow JSON imports "esModuleInterop": true, // Compatibility for CommonJS modules "skipLibCheck": true // Skip type checking of .d.ts files }}{ "compilerOptions": { "target": "ES2020", "module": "CommonJS", "outDir": "./dist", "rootDir": "./src", "strict": true, "moduleResolution": "node", "esModuleInterop": true, "skipLibCheck": true, "forceConsistentCasingInFileNames": true, "resolveJsonModule": true, "declaration": true, "declarationMap": true, "sourceMap": true }, "include": ["src"], "exclude": ["node_modules", "dist"]}{ "compilerOptions": { "target": "ES2022", "module": "ESNext", "outDir": "./dist", "rootDir": "./src", "strict": true, "moduleResolution": "bundler", "allowJs": true, "skipLibCheck": true }, "include": ["src"], "exclude": ["node_modules", "dist"]}# Uses tsconfig.json automaticallynpx tsc
# Verbose output to see what's happeningnpx tsc --listFilesnpx tsc --watch# ornpx tsc -wVery useful during development. The compiler runs every time you save a .ts file.
# Even when using tsconfig.jsonnpx tsc src/main.tsnpx tsc --noEmitUseful in CI/CD pipelines to catch type errors without generating files.
npx tsc --showConfigShows the final merged configuration that TypeScript is using.
{ "include": [ "src/**/*", // Everything in src (recursive) "src/**/*.ts", // Only .ts files "src/pages/*.ts", // Only files directly in pages/ "src/**/*.{ts,tsx}" // Both .ts and .tsx files ], "exclude": [ "**/node_modules/**", "**/dist/**", "**/*.test.ts", "**/*.spec.ts" ]}{ "include": [ "src/**/*", "tests/**/*.test.ts" ], "exclude": [ "node_modules", "dist", "build", ".git", ".vscode" ]}Check:
include pattern?exclude?npx tsc --listFiles to see all files being processedCheck:
rootDir correctly points to source rootoutDir is where you expect outputsrc/utils/helper.ts → dist/utils/helper.jsCheck:
moduleResolution setting (usually "node" or "bundler")baseUrl for path mappingpaths configuration for aliasesnpx tsc --showConfig -p .Shows the complete final configuration being used.