加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 综合聚焦 > 服务器 > 安全 > 正文

angular – 为什么打字工具故意创建重复的打字集?

发布时间:2020-12-17 17:35:01 所属栏目:安全 来源:网络整理
导读:阅读 Angular 2 Quickstart我在 TypeScript Configuration下遇到了这一节: Typing file collisions The TypeScript compiler does not tolerate redefinition of a type. For example,it throws an error if it’s given two definitions for the Promise t
阅读 Angular 2 Quickstart我在 TypeScript Configuration下遇到了这一节:

Typing file collisions

The TypeScript compiler does not tolerate redefinition of a type. For
example,it throws an error if it’s given two definitions for the
Promise type.

Double definitions are common. In fact,the typings tool deliberately
creates duplicate sets of typings
(for reasons best explained
elsewhere). Look in the project structure for the typings folder where
we should find something like:

typings
  browser
    ambient
      es6-shim
        es6-shim.d.ts
  main
    ambient
      es6-shim
        es6-shim.d.ts
  browser.d.ts
  main.d.ts

The es6-shim typings are duplicated and the browser.d.ts and main.d.ts
have overlapping content.

如果我读了typings readme,它说:

If you’re building a front-end package it’s recommended you use typings/browser.d.ts. The browser typings are compiled by following the browser field overrides.

问题:

为什么typings tool故意创建重复的打字集?

为什么建议您使用typings / browser.d.ts作为前端软件包?

我的猜测是因为支持浏览器字段可以创建不同的类型?

如果是这样,什么是浏览器字段以及它改变打字的方式?

解决方法

你的猜测是正确的.类型识别包可以在浏览器和其他位置以不同的方式运行.对于大多数常见的包,这个功能是不必要的,因为同构JS很时髦,许多包在所有JS环境中都具有相同的功能.

但是,如果我的代码是故意检查环境的功能,或者如果我想阻止用户使用浏览器中已损坏的功能,那么将有所帮助.

这是一个例子.我有一个颜色选择器包.这个包,如果我在桌面上,将允许我从我的屏幕上的任何地方选择颜色.显然,这依赖于系统级API,浏览器无法使用.另一方面,我的浏览器可以在浏览器窗口中选择颜色.我没有发布一个全新的包,而是向程序员展示不同的类型,以便他们根据环境知道允许哪些功能.

最终,您的成本很低(除了计算机上的文件空间)以及可能无法实现的功能.

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读