[英]Errors when transpiling ts files for an Angular2 application
I try to use TypeScript with Angular. 我尝试将TypeScript与Angular结合使用。 For this, I transpile my ts files using the tsc command and I have some errors.
为此,我使用tsc命令转换ts文件,但出现一些错误。 That said, the files are actually transpiled into JavaScript and I can make work my application but these errors are a bit strange....
就是说,这些文件实际上已经被转换为JavaScript,并且我可以使我的应用程序正常工作,但是这些错误有点奇怪。
Here is what I have: 这是我所拥有的:
app.ts(1,1): error TS1148: Cannot compile modules unless the '--module' flag is provided.
app.ts(1,42): error TS2307: Cannot find module 'angular2/angular2'.
app.ts(13,7): error TS1219: Experimental support for decorators is a feature that is subject to change in a future release. Specify '--experimentalDecorators' to remove this warning.
Here is the content of the tsd.json
file: 这是
tsd.json
文件的内容:
{
"version": "v4",
"repo": "borisyankov/DefinitelyTyped",
"ref": "master",
"path": "typings",
"bundle": "typings/tsd.d.ts",
"installed": {
"angular2/angular2.d.ts": {
"commit": "78ba6e41543e5ababbd1dda19797601be3c1f304"
}
}
}
Here is the content of the tsdconfig.json
file: 这是
tsdconfig.json
文件的内容:
{
"compilerOptions" : {
"emitDecoratorMetadata": true,
"module": "commonjs",
"target": "es5"
},
"files" : [
"app.ts",
"typings/angular2/angular2.d.ts"
]
}
To compile, I execute the command: tsc --watch *.ts
. 要编译,我执行命令:
tsc --watch *.ts
。 My ts files are located at the root of my project. 我的ts文件位于项目的根目录。
Thanks very much for your help, Thierry 非常感谢您的帮助,蒂埃里
First, if you specify file(s) in tsc command, tsconfig.json
file is ignored . 首先,如果您在tsc命令中指定文件,则
tsconfig.json
文件将被忽略 。 You can learn more about it here . 您可以在此处了解更多信息。 So you should invoke command:
tsc -w
. 因此,您应该调用命令:
tsc -w
。 Second, you do not have to include typings in your files, they are just for intellisense in your editor(and angular2 includes its typings by default). 其次,您不必在文件中包含类型,它们仅用于编辑器中的智能感知(默认情况下,angular2包括其类型)。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.