Here is SystemJS + TypeScript plunk,從official Angular plunk template創建。忽略TypeScript類型錯誤
,因爲它表明,它忽略所有打字稿類型的錯誤,已記錄到控制檯的唯一事情就是foo
:
main.ts
const foo: boolean = 'foo';
console.log(foo);
config.js
System.config({
//use typescript for compilation
transpiler: 'typescript',
//typescript compiler options
typescriptOptions: {
emitDecoratorMetadata: true
},
paths: {
'npm:': 'https://unpkg.com/'
},
//map tells the System loader where to look for things
map: {
'app': './src',
...
},
//packages defines our app package
packages: {
app: {
main: './main.ts',
defaultExtension: 'ts'
},
...
}
});
index.html
...
<script src="https://unpkg.com/[email protected]/dist/system.js"></script>
<script src="config.js"></script>
<script>
System.import('app')
.catch(console.error.bind(console));
</script>
...
一般來說,我寧願使用TypeScript來停止應用程序的執行並拋出類型錯誤。
這個設置有什麼問題?爲什麼要抑制TypeScript錯誤?這個設置如何改變?
設置沒有問題,在瀏覽器中進行類型檢查並不容易,因爲某人必須以某種方式在瀏覽器中提供編譯器所需的所有類型定義。爲了避開這個問題,SystemJS使用'transpileModule()'打字稿方法,它不會按照設計進行類型檢查。對於0.19,你可以使用[plugin-typescript](https://github.com/frankwallis/plugin-typescript)並將它的'typeCheck'選項設置爲true,但是從SystemJS 0.20開始[這不再可能](https ://github.com/frankwallis/plugin-typescript/issues/194)。我切換到webpack。 – artem
@artem謝謝,很高興知道。 0.20是一個顯示限制器有幾個原因,但可能[仍有希望](https://github.com/frankwallis/plugin-typescript/issues/185#issuecomment-275999466),我不確定。你知道如何更新plunk來使用plugin-typescript嗎? [我結束了](https://plnkr.co/edit/xNOvL4efra2IGEUaQxpe?'TypeError:AMD模塊https://unpkg.com/[email protected]/lib/typescript.js沒有定義錯誤。 – estus