的設置:
我創建了一個打字稿文件(String.ts)來擴展字符串:打字稿:無法找到參照編譯時
interface StringConstructor {
isNullOrEmpty(str: string): boolean;
isNullOrWhiteSpace(str: string): boolean;
}
String.isNullOrEmpty = (str: string) => !str;
String.isNullOrWhiteSpace = (str: string) => { return (String.isNullOrEmpty(str)) ? false : str.replace(/\s/g, '').length < 1 };
,我創建的tsconfig.json文件包含:
{
"compilerOptions": {
"noImplicitAny": false,
"strict": true,
"noEmitOnError": true,
"module": "amd",
"removeComments": true,
"target": "es5",
"declaration": true,
"outFile": "./Common.js", --> Only this line changes in other tsconfig.json files (+ does not exist in highest located tsconfig.json file)
"inlineSourceMap": true,
"inlineSources": true,
"lib": [
"dom",
"es5",
"es2015.promise"
]
},
"exclude": [
"node_modules",
"wwwroot"
]
}
文件結構:
- 通用(文件夾)
〜String.ts
〜<其他文件>
〜tsconfig.json - Bussines(文件夾)
〜app.ts - >這裏我們使用String.IsNullOrWhiteSpace
〜<其他文件>
〜tsconfig.json - tsconfig.json
問題(按以下順序)
1)當我有一個tsconfig.json(最高級別),一切OK編譯
2)當我在公共添加tsconfig.json,一切OK編譯
3)當我在Business中添加tsconfig.json時,出現無法找到String.isNullOrWhiteSpace的編譯錯誤。
任何人都知道問題是什麼以及如何解決它?
(如果需要更多的信息...讓我知道!)
爲什麼你需要多個'tsconfigs'? – Wernerson
例如,將Common文件夾中的所有文件編譯爲一個文件並提高性能。通過將它們分割成多個文件,我仍然保持良好的可維護性代碼 – RubenHerman
我也喜歡將我的接口分割成單獨的文件,但是當我們編譯這個時,我們得到一個空的* .js文件 - >因此編譯一個文件中的所有內容解決了這個問題。但是,如果我們將所有內容編譯到這個文件(最高級別),那麼在其他應用程序中也可以重複使用它。 – RubenHerman