当前位置:网站首页>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
边栏推荐
- The vscode ipynb file does not have code highlighting and code completion solutions
- 源码剖析Redis中如何使用跳表的
- What are the most popular recruitment technical skills in 2022? You can't think of it
- QPushButton slot function is triggered multiple times
- mysql5. 7. X data authorization leads to 1141
- mariadb数据库的主从复制
- Routing parameters
- To understand Devops, you must read these ten books!
- Various ways of writing timed tasks of small programs
- Domain driven model DDD (III) -- using saga to manage transactions
猜你喜欢

Three 之 three.js (webgl)简单实现根据点绘制线/弧线(基于LineGeometry / Line2 / LineMaterial,绘制两点基于圆心的弧线段)

Solution of how to log in with mobile phone verification code in wireless network

Good test data management, in the end how to do?

One month countdown, pgconf What are the highlights of the latest outlook of asia2021 Asian Conference?

Basic theory of Flink

Restful toolkit of idea plug-in

What are the most popular recruitment technical skills in 2022? You can't think of it

好的测试数据管理,到底要怎么做?

A trinomial expression that causes a null pointer

Redis data type usage scenario
随机推荐
[2021] Spatio-Temporal Graph Contrastive Learning
Detailed explanation of concurrent topics
Cloud computing and cloud native architecture design of openshift
Three 之 three.js (webgl)简单实现根据点绘制线/弧线(基于LineGeometry / Line2 / LineMaterial,绘制两点基于圆心的弧线段)
To understand Devops, you must read these ten books!
2021-09-23
Servlet3 0 + event driven for high performance long polling
At pgconf Asia Chinese technology forum, listen to Tencent cloud experts' in-depth understanding of database technology
Musk and twitter storm drama
Qingdao agile tour, coming!
API slow interface analysis
学习笔记:Unity CustomSRP-11-Post Processing---Bloom
Basic theory of Flink
Live delivery form template - automatically display pictures - automatically associate series products
Study notes: unity customsrp-11-post processing --- bloom
How to add beautiful code blocks in word | a very complete method to sort out and compare
A trinomial expression that causes a null pointer
Tensorflow realizes web face login system
学习笔记:Unity CustomSRP-10-Point and Spot Shadows
Mairadb数据库基本操作之数据管理