简体   繁体   English

为什么在Angular 2项目中需要`typings.json`文件?

[英]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.

相关问题 typings.json没有得到更新的打字安装 - 边框 - typings.json not getting updated typings install --ambient 我需要json.js文件吗? - do i need json.js file? 我是否需要在 Jmeter 项目中导入任何 Jar 文件才能使用“import groovy.json.*”?? 我该怎么做? - Do I need to import any Jar file in Jmeter project in order to use " import groovy.json.*"?? how should I do that? 如何在项目中放置 JSON 文件? - How do I place a JSON file in a project? 如何为Angular 6项目一次从JSON文件中获取一定数量的信息? - How do I get information from a JSON file a certain amount at a time for Angular 6 project? 如何在Angular中读取JSON文件? - How do I read a JSON file in Angular? 为什么通过Angular $ http解析此示例Twitter json文件失败,我该如何解决? - Why does parsing this example Twitter json file via Angular $http fail and what can I do to fix it? 为什么我需要从.net编辑JSON以便Android接受它? - Why do I need to edit JSON from .net for android to accept it? 为什么我有时需要使用JSON.stringify,有时候不需要 - Why do I need to use sometimes JSON.stringify and sometimes not 我的 launch.json 文件中需要这么多块吗? - Do I need this many blocks in my launch.json file?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM