当前位置:网站首页>TypeScript获取函数参数类型
TypeScript获取函数参数类型
2022-07-06 15:10:00 【用户6256742】
现在有一个函数update,我们想要获取他的参数类型,你应该怎么做呢?这个时候我们需要就要用到Parameters
function updata(state) {
return {
router: state.router
}
}获取参数类型:
type ArrType = Parameters<typeof state>
// ArrType => [state: any]如果想获取state的类型呢?这个时候需要用到infer
type GetType<T> = T extends (arg: infer P) => void ? P : string;
type StateType = GetType<typeof state>
// StateType => any
// 因为state没有设置类型,所以ts推断state的类型为any把这段代码翻译一下: (arg: infer P):arg的类型待推断为P 整段代码的意思:如果T能赋值给(arg: infer P) => void,则返回P,否则返回string
如果想要获取函数的返回值类型,需要使用typescript提供的内置方法ReturnType
type Return = ReturnType<typeof state>
// ReturnType =>
// {
// router: any;
//}边栏推荐
- The ceiling of MySQL tutorial. Collect it and take your time
- General implementation and encapsulation of go diversified timing tasks
- 剪映+json解析将视频中的声音转换成文本
- CCNA Cisco network EIGRP protocol
- ResNet-RS:谷歌领衔调优ResNet,性能全面超越EfficientNet系列 | 2021 arxiv
- UDP编程
- Management background --1 Create classification
- pytorch_ Yolox pruning [with code]
- 【踩坑合辑】Attempting to deserialize object on CUDA device+buff/cache占用过高+pad_sequence
- Notes de développement du matériel (10): flux de base du développement du matériel, fabrication d'un module USB à RS232 (9): création de la Bibliothèque d'emballage ch340g / max232 SOP - 16 et Associa
猜你喜欢

剑指offer刷题记录1

Management background --5, sub classification

Leetcode exercise - Sword finger offer 26 Substructure of tree

CCNA Cisco network EIGRP protocol

Aardio - 通过变量名将变量值整合到一串文本中

MySQL数据库基本操作-DML

Aardio - 利用customPlus库+plus构造一个多按钮组件
![[leetcode] 19. Delete the penultimate node of the linked list](/img/ab/25cb6d6538ad02d78f7d64b2a2df3f.png)
[leetcode] 19. Delete the penultimate node of the linked list

手写ABA遇到的坑

树的先序中序后序遍历
随机推荐
Comparison between variable and "zero value"
【数字IC手撕代码】Verilog无毛刺时钟切换电路|题目|原理|设计|仿真
NPDP certification | how do product managers communicate across functions / teams?
[leetcode daily clock in] 1020 Number of enclaves
uniapp滑动到一定的高度后固定某个元素到顶部效果demo(整理)
Mise en place d'un environnement de développement OP - tee basé sur qemuv8
Daily question 1: force deduction: 225: realize stack with queue
[leetcode] 19. Delete the penultimate node of the linked list
自制J-Flash烧录工具——Qt调用jlinkARM.dll方式
Applet system update prompt, and force the applet to restart and use the new version
MySQL教程的天花板,收藏好,慢慢看
Data processing skills (7): MATLAB reads the data in the text file TXT with mixed digital strings
UDP编程
CCNA Cisco network EIGRP protocol
中国1,4-环己烷二甲醇(CHDM)行业调研与投资决策报告(2022版)
Sword finger offer question brushing record 1
LeetCode 练习——剑指 Offer 26. 树的子结构
PVL EDI project case
The ceiling of MySQL tutorial. Collect it and take your time
2022-07-05 use TPCC to conduct sub query test on stonedb