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