当前位置:网站首页>d.ts---更详细的知识还是需要看官网的介绍(声明文件章节)
d.ts---更详细的知识还是需要看官网的介绍(声明文件章节)
2022-04-23 05:20:00 【process1212】
d.ts是啥东西
js文件缺少了类型,ts那么多的类型数据就都没了,所以需要一个d.ts文件来标记某个js库里面的对象的类型。
typings就是网络上的d.ts数据库。
简单来说,就是描述库中成员类型来给TS用的。
好处:代码安全,编辑器能够智能提醒
还会定义很多export的数据类型,和interface供外部模块调用。很显然就是数据规范。
声明文件
使用第三方库的时候,需要引用它的声明文件
$('#foo');
// or
jQuery('#foo');
使用declare
关键字来定义它的类型,帮助TS判断传入类型:
declare var jQuery: (selector: string) => any;
jQuery('#foo');
declare
定义的类型只会用于编译时的检查,编译结果中会被删除。
类型声明放到一个单独的文件中,这就是声明文件。
// jQuery.d.ts
declare var jQuery: (string) => any;
使用///
表示引用了声明文件:
/// <reference path="./jQuery.d.ts" />
jQuery('#foo');
索引签名
可以用字符串访问js中的对象,保存对其他对象的引用。
版权声明
本文为[process1212]所创,转载请带上原文链接,感谢
https://blog.csdn.net/qq_33589252/article/details/85535965
边栏推荐
- Minimum spanning tree -- unblocked project hdu1863
- 领域驱动模型DDD(三)——使用Saga管理事务
- Mac enters MySQL terminal command
- 使用 Kears 实现ResNet-34 CNN
- Three of three JS (WEB GL) model deletion / scene emptying / simple sorting of memory release
- MySQL foreign key constraint
- Various ways of writing timed tasks of small programs
- Docker installation and mysql5 7 installation
- Servlet3 0 + event driven for high performance long polling
- Devops life cycle, all you want to know is here!
猜你喜欢
Power consumption parameters of Jinbei household mute box series
好的测试数据管理,到底要怎么做?
Solution of how to log in with mobile phone verification code in wireless network
4 个最常见的自动化测试挑战及应对措施
Minimum spanning tree -- unblocked project hdu1863
青岛敏捷之旅,来了!
What are the reasons for the failure of digital transformation?
Jupyter notebook crawling web pages
JS Array常见方法
Live delivery form template - automatically display pictures - automatically associate series products
随机推荐
How to add beautiful code blocks in word | a very complete method to sort out and compare
Low code and no code considerations
4 个最常见的自动化测试挑战及应对措施
The concept of meta universe is popular. Is virtual real estate worth investing
#define 定义常量和宏,指针和结构体
MySQL external connection, internal connection, self connection, natural connection, cross connection
Study notes: unity customsrp-11-post processing --- bloom
Project manager's thinking mode worth trying: project success equation
Minimum spanning tree -- unblocked project hdu1863
Kubectl command automatic replenishment
《2021年IT行业项目管理调查报告》重磅发布!
Three of three JS (webgl) simple sorting of rotation attribute function, and a simple case of rotating around the axis based on this
Five key technologies to improve the devsecops framework
PIP free export with path (@ file: / / /) notes
At pgconf Asia Chinese technology forum, listen to Tencent cloud experts' in-depth understanding of database technology
JS Array常见方法
Anti crawler (0): are you still climbing naked with selenium? You're being watched! Crack webdriver anti crawler
Define defines constants and macros, pointers and structures
Qingdao agile tour, coming!
Interview summary