当前位置:网站首页>模块代码的类型描述文件
模块代码的类型描述文件
2022-04-22 18:41:00 【小二李】
本篇文章将介绍TypeScript中模块代码的类型描述文件相关知识。
npm安装jquery库。
cnpm i jquery -S
在ts文件中引入jquery库时提示以下信息

新建类型描述文件jquery.d.ts,用于定义ts文件中使用到的jquery模块定义。
jquery.d.ts
// ES6模块化:定义名称为jquery的模块
declare module 'jquery' {
// 定义名称为$, 参数为函数类型,返回值为void的函数
function $(readyFunc: () => void): void;
// 定义名称为$, 参数为string,内部包含一个接收string参数,返回值为void的函数
function $(selector: string): {
html: (html: string) => void;
}
// 命名空间
namespace $ {
namespace fn {
class init{}
}
}
// 导出自定义函数
export = $;
}
这时候在ts文件中就可以识别jquery模块了,也可以使用模块中定义的全局函数和命名空间。
demo.ts
import $ from 'jquery';
$(function () {
$('body').html('<div>123</div>')
new $.fn.init()
})
版权声明
本文为[小二李]所创,转载请带上原文链接,感谢
https://blog.csdn.net/weixin_43800535/article/details/124336912
边栏推荐
- The balance between safety and opportunity -- the choice and thinking of St stock investment target
- 带你了解极具弹性的Spark架构的原理
- Do you know how many sensors are on your phone?
- Pytoch Note58 CNN可视化
- [drive] TX2 transplants EC20 startup module
- PHP 零基础入门笔记(12):数组 array
- 【Proteus仿真】51单片机8路舵机点动±90°点动控制
- jvm 组成
- DL yolov3: translation and interpretation of yolov3: an incremental improvement
- WiFi Technology Overview: WiFi things
猜你喜欢

免外围电路ESP32/ESP8266系列单片机串口一键下载方案

Applets -- components

跨链资产交互——如何在Moonriver上转移KSM

The Sandbox 与 Apex Athletes 达成合作关系

山东大学项目实训树莓派提升计划二期(九)继承和多态

Kellerman Software .NET SFTP Library

PostgreSQL 15 will soon support merge statements in the SQL standard

MFC principle and method (II)

redis发布订阅

18730 coloring problem (two ways of writing fast power)
随机推荐
PostgreSQL 15即将支持SQL标准中的MERGE语句
redis发布订阅
Redis series (5) - common cache problems
Classes and objects - 5
【接口测试基础】第八篇 | PostMan常用断言及断言的工作原理
leetcode - 234. 回文链表
不产桩不建桩,充电服务商NaaS靠什么崛起?
浅析局域网聊天软件的能力
mysql 之 MHA
JVM composition
Hackmyvm (XXV) helium, series of articles continuously updated
[most complete in the whole network] jsr303 parameter verification and global exception handling (don't use if to judge parameters from theory to practice)
目前国产电脑硬件的现状是怎样的?
Talk about the pit of cache Boolean value
Why don't I use flomo anymore
Detailed understanding of gaussdb and how to do data migration [play with Huawei cloud]
Model Inspector — 软件模型静态规范检查工具
【接口测试基础】第九篇 | 详解PostMan全局变量和环境变量
Domestic chip dp9637-k bus transceiver replaces l9637d chip and si9241
C语言的预编译(预处理)#define