当前位置:网站首页>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
边栏推荐
- Interesting prime number problem hdu5750
- 开源规则引擎——ice:致力于解决灵活繁复的硬编码问题
- The source of anxiety of graduating college students looking for technology development jobs
- Basic knowledge of vegetable chicken database
- Flip coin (Blue Bridge Cup)
- Master-slave replication of MariaDB database
- 領域驅動模型DDD(三)——使用Saga管理事務
- Summary of MySQL knowledge points
- Swing display time (click once to display once)
- 即将毕业的大学生找技术开发工作的焦虑根源
猜你喜欢

The WebService interface writes and publishes calls to the WebService interface (I)

Project manager's thinking mode worth trying: project success equation

My old programmer's perception of the dangers and opportunities of the times?

Qingdao agile tour, coming!

Good simple recursive problem, string recursive training

Redis persistence

低代码和无代码的注意事项

Let the LAN group use the remote device

开源规则引擎——ice:致力于解决灵活繁复的硬编码问题

Low code and no code considerations
随机推荐
Various ways of writing timed tasks of small programs
Live delivery form template - automatically display pictures - automatically associate series products
Cloud computing and cloud native architecture design of openshift
Top 25 Devops tools in 2021 (Part 2)
MySQL basics 3
何时适合进行自动化测试?(下)
The introduction of lean management needs to achieve these nine points in advance
C language hash dictionary and notes
领域驱动模型DDD(三)——使用Saga管理事务
One month countdown, pgconf What are the highlights of the latest outlook of asia2021 Asian Conference?
Chapter I overall project management of information system project manager summary
云计算与云原生 — OpenShift 的架构设计
[2022 ICLR] Pyramid: low complexity pyramid attention for long range spatiotemporal sequence modeling and prediction
Some experience in using MySQL / tidb database [slowly updating...]
Project manager's thinking mode worth trying: project success equation
To understand Devops, you must read these ten books!
MFC实现资源单独Dll实现
Servlet3 0 + event driven for high performance long polling
MySQL external connection, internal connection, self connection, natural connection, cross connection
Collaboration future object and concurrent futures