[英]Why do i need `typings.json` file in an Angular 2 project?
Why do i need typings.json
like below: 为什么我需要如下的typings.json
:
{
"globalDependencies": {
"core-js": "registry:dt/core-js#0.0.0+20160725163759",
"jasmine": "registry:dt/jasmine#2.2.0+20160621224255",
"node": "registry:dt/node#6.0.0+20160831021119"
}
}
for an Angular2 project? Angular2项目? I've got: 我有:
typings.json provides additional definition files for libraries that the TypeScript compiler doesn't natively recognize. types.json为TypeScript编译器本机无法识别的库提供了其他定义文件。
which, as a newbie I don't clearly understand. 作为一个新手,我不清楚。
So, I've found this: 因此,我发现了这一点:
Any JavaScript libraries, such as jQuery, the Jasmine testing library, and Angular, extend the JavaScript environment with features and syntax that the TypeScript compiler doesn't recognize natively. 任何JavaScript库(例如jQuery,Jasmine测试库和Angular)都使用TypeScript编译器无法原生识别的功能和语法扩展了JavaScript环境。 When the compiler doesn't recognize something, it throws an error . 当编译器无法识别某些内容时,它将引发错误 。
So, If we wrote a library which may use by other persons in their projects along with TypeScript, the TypeScript throws an error . 因此,如果我们编写了一个供其他人在他们的项目中使用的库以及TypeScript,则TypeScript会引发错误 。 To resolve it, we have to write the TypeScript type definition files (.d.ts files) in the library directory. 要解决此问题,我们必须在库目录中编写TypeScript类型定义文件(.d.ts文件) 。
AngularJS along with most of the libraries already doing this.But, Libraries like "core-js" and "jasmine" do not include d.ts files in their npm packages. AngularJS和大多数库已经在执行此操作。但是,“ core-js”和“ jasmine”之类的库在其npm软件包中不包含d.ts文件。 Fortunately, either their authors or community contributors have created separate .d.ts
files for these libraries and published them in well-known locations. 幸运的是,他们的作者或社区贡献者已为这些库创建了单独的.d.ts
文件,并将它们发布在了知名的位置。 The typings tool can find and fetch these files for you. 打字工具可以为您查找和获取这些文件。
So, we have to write typings.json
file to get the correct type definition files to run the project smoothly. 因此,我们必须编写typings.json
文件来获取正确的类型定义文件,以使项目顺利运行。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.