Install & Compile

# Install TypeScript as a dev dependency
npm install typescript --save-dev

# Compile a specific TypeScript file (e.g., app.ts)
npx tsc app.ts

tsc / tsserver

Configuration

Create a tsconfig.json in your project root. This configuration enables strict type-checking and modern JavaScript features.

{
  "compilerOptions": {
    "target": "ES2020",                          // Use modern JS features
    "module": "ESNext",                          // Use the latest module system
    "moduleResolution": "node",                  // Node module resolution
    "outDir": "./dist",                          // Compiled output directory
    "rootDir": "./",                             // Root of your source files
    "strict": true,                              // Enable all strict type-checking options
    "esModuleInterop": true,                     // Allow default imports from non-ES modules
    "skipLibCheck": true,                        // Skip type checking of declaration files
    "forceConsistentCasingInFileNames": true,    // Enforce consistent file naming
    "resolveJsonModule": true,                   // Import JSON files as modules
    "allowSyntheticDefaultImports": true,        // Allow default imports even if module doesn't have one
    "strictNullChecks": true,                    // Null and undefined are separate types
    "noImplicitAny": true,                       // Disallow variables with an implied any type
    "noUnusedLocals": true,                      // Error on unused locals
    "noUnusedParameters": true,                  // Error on unused function parameters
    "noFallthroughCasesInSwitch": true           // Prevent fall-through in switch cases
  },
  "include": ["src/**/*.ts"],
  "exclude": ["node_modules", "dist"]
}