天天看點

Angular sandbox項目的tsconfig.json内容一覽

{
  "compileOnSave": false,
  "compilerOptions": {
    "baseUrl": "./",
    "outDir": "./dist/out-tsc",
    "sourceMap": true,
    "declaration": false,
    "downlevelIteration": true,
    "experimentalDecorators": true,
    "module": "esnext",
    "moduleResolution": "node",
    "importHelpers": true,
    "target": "es2015",
    "lib": [
      "es2018",
      "dom"
    ]
  },
  "angularCompilerOptions": {
    "fullTemplateTypeCheck": true,
    "strictInjectionParameters": true
  }
}
      
Angular sandbox項目的tsconfig.json内容一覽

target: es2015

指定 ECMAScript 目标版本: ‘ES3’ (default), ‘ES5’, ‘ES2015’, ‘ES2016’, ‘ES2017’, or ‘ESNEXT’

module: esnext

指定使用子產品: ‘commonjs’, ‘amd’, ‘system’, ‘umd’ or ‘es2015’

lib

指定要包含在編譯中的庫檔案

declaration

如果為true,生成相應的 ‘.d.ts’ 檔案

importHelpers

從 tslib 導入輔助工具函數

更詳細的說明,參考下面的spec:

{
  "compilerOptions": {

    /* 基本選項 */
    "target": "es5",                       // 指定 ECMAScript 目标版本: 'ES3' (default), 'ES5', 'ES2015', 'ES2016', 'ES2017', or 'ESNEXT'
    "module": "commonjs",                  // 指定使用子產品: 'commonjs', 'amd', 'system', 'umd' or 'es2015'
    "lib": [],                             // 指定要包含在編譯中的庫檔案
    "allowJs": true,                       // 允許編譯 javascript 檔案
    "checkJs": true,                       // 報告 javascript 檔案中的錯誤
    "jsx": "preserve",                     // 指定 jsx 代碼的生成: 'preserve', 'react-native', or 'react'
    "declaration": true,                   // 生成相應的 '.d.ts' 檔案
    "sourceMap": true,                     // 生成相應的 '.map' 檔案
    "outFile": "./",                       // 将輸出檔案合并為一個檔案
    "outDir": "./",                        // 指定輸出目錄
    "rootDir": "./",                       // 用來控制輸出目錄結構 --outDir.
    "removeComments": true,                // 删除編譯後的所有的注釋
    "noEmit": true,                        // 不生成輸出檔案
    "importHelpers": true,                 // 從 tslib 導入輔助工具函數
    "isolatedModules": true,               // 将每個檔案做為單獨的子產品 (與 'ts.transpileModule' 類似).

    /* 嚴格的類型檢查選項 */
    "strict": true,                        // 啟用所有嚴格類型檢查選項
    "noImplicitAny": true,                 // 在表達式和聲明上有隐含的 any類型時報錯
    "strictNullChecks": true,              // 啟用嚴格的 null 檢查
    "noImplicitThis": true,                // 當 this 表達式值為 any 類型的時候,生成一個錯誤
    "alwaysStrict": true,                  // 以嚴格模式檢查每個子產品,并在每個檔案裡加入 'use strict'

    /* 額外的檢查 */
    "noUnusedLocals": true,                // 有未使用的變量時,抛出錯誤
    "noUnusedParameters": true,            // 有未使用的參數時,抛出錯誤
    "noImplicitReturns": true,             // 并不是所有函數裡的代碼都有傳回值時,抛出錯誤
    "noFallthroughCasesInSwitch": true,    // 報告 switch 語句的 fallthrough 錯誤。(即,不允許 switch 的 case 語句貫穿)

    /* 子產品解析選項 */
    "moduleResolution": "node",            // 選擇子產品解析政策: 'node' (Node.js) or 'classic' (TypeScript pre-1.6)
    "baseUrl": "./",                       // 用于解析非相對子產品名稱的基目錄
    "paths": {},                           // 子產品名到基于 baseUrl 的路徑映射的清單
    "rootDirs": [],                        // 根檔案夾清單,其組合内容表示項目運作時的結構内容
    "typeRoots": [],                       // 包含類型聲明的檔案清單
    "types": [],                           // 需要包含的類型聲明檔案名清單
    "allowSyntheticDefaultImports": true,  // 允許從沒有設定預設導出的子產品中預設導入。

    /* Source Map Options */
    "sourceRoot": "./",                    // 指定調試器應該找到 TypeScript 檔案而不是源檔案的位置
    "mapRoot": "./",                       // 指定調試器應該找到映射檔案而不是生成檔案的位置
    "inlineSourceMap": true,               // 生成單個 soucemaps 檔案,而不是将 sourcemaps 生成不同的檔案
    "inlineSources": true,                 // 将代碼與 sourcemaps 生成到一個檔案中,要求同時設定了 --inlineSourceMap 或 --sourceMap 屬性

    /* 其他選項 */
    "experimentalDecorators": true,        // 啟用裝飾器
    "emitDecoratorMetadata": true          // 為裝飾器提供中繼資料的支援
  }
}      

繼續閱讀