tsconfig & Setup — TypeScript

File tsconfig.json mengatur bagaimana TypeScript bekerja di project kamu. Membuat tsconfig: $ npx tsc --init Opsi paling penting: { "compilerOptions": { "target

File tsconfig.json mengatur bagaimana TypeScript bekerja di project kamu.

Membuat tsconfig:

$ npx tsc --init

Opsi paling penting:

{
  "compilerOptions": {
    "target": "ES2020",        // JavaScript output target
    "module": "ESNext",         // sistem module
    "strict": true,             // aktifkan SEMUA strict checks ✅
    "outDir": "./dist",         // folder output
    "rootDir": "./src",         // folder source code
    "esModuleInterop": true,    // import CommonJS modules
    "skipLibCheck": true,       // percepat compile
    "forceConsistentCasingInFileNames": true
  },
  "include": ["src/**/*"],      // file yang dicompile
  "exclude": ["node_modules"]   // file yang diabaikan
}

Strict mode ("strict": true) mengaktifkan:

Tips per framework:

Framework Target Module
React (Vite) ESNext ESNext
Node.js ES2022 NodeNext
Library ES2020 CommonJS + ESNext

Menjalankan TypeScript:

Tips: Selalu gunakan "strict": true. Lebih baik strict dari awal daripada menambahkan nanti ke project yang sudah besar.

Yang akan kamu pelajari