当前位置:网站首页>Typescript get function parameter type
Typescript get function parameter type
2022-07-06 22:33:00 【User 6256742】
Now there's a function update, We want to get its parameter type , What should you do ? At this time, we need to use Parameters
function updata(state) {
return {
router: state.router
}
}
Get parameter type :
type ArrType = Parameters<typeof state>
// ArrType => [state: any]
If you want to get state The type of ? You need to use infer
type GetType<T> = T extends (arg: infer P) => void ? P : string;
type StateType = GetType<typeof state>
// StateType => any
// because state No type set , therefore ts infer state The type of any
Translate this code : (arg: infer P):arg The type of is to be inferred as P The meaning of the whole code : If T Can be assigned to (arg: infer P) => void, Then return to P, Otherwise return to string
If you want to get the Return value type , Need to use typescript Built in methods provided ReturnType
type Return = ReturnType<typeof state>
// ReturnType =>
// {
// router: any;
//}
边栏推荐
- 柔性数组到底如何使用呢?
- rust知识思维导图xmind
- Installation and use of labelimg
- NetXpert XG2帮您解决“布线安装与维护”难题
- i. Mx6ull build boa server details and some of the problems encountered
- Improving Multimodal Accuracy Through Modality Pre-training and Attention
- Sizeof keyword
- 2014阿里巴巴web前实习生项目分析(1)
- MySQL ---- first acquaintance with MySQL
- 基於 QEMUv8 搭建 OP-TEE 開發環境
猜你喜欢
C# 三种方式实现Socket数据接收
第3章:类的加载过程(类的生命周期)详解
将MySQL的表数据纯净方式导出
The nearest common ancestor of binary (search) tree ●●
[linear algebra] determinant of order 1.3 n
2022-07-04 the high-performance database engine stonedb of MySQL is compiled and run in centos7.9
自制J-Flash烧录工具——Qt调用jlinkARM.dll方式
Crawler obtains real estate data
How to confirm the storage mode of the current system by program?
Data processing skills (7): MATLAB reads the data in the text file TXT with mixed digital strings
随机推荐
Report on technological progress and development prospects of solid oxide fuel cells in China (2022 Edition)
Chapter 4: talk about class loader again
Aardio - 通过变量名将变量值整合到一串文本中
Heavyweight news | softing fg-200 has obtained China 3C explosion-proof certification to provide safety assurance for customers' on-site testing
使用云服务器搭建代理
[Digital IC hand tearing code] Verilog burr free clock switching circuit | topic | principle | design | simulation
Leetcode: interview question 17.24 Maximum cumulative sum of submatrix (to be studied)
Advantages of link local address in IPv6
SQL Server生成自增序号
[linear algebra] determinant of order 1.3 n
第3章:类的加载过程(类的生命周期)详解
TypeScript获取函数参数类型
[leetcode] 19. Delete the penultimate node of the linked list
Memorabilia of domestic database in June 2022 - ink Sky Wheel
Lora sync word settings
【LeetCode】19、 删除链表的倒数第 N 个结点
Config:invalid signature solution and troubleshooting details
2022-07-05 使用tpcc对stonedb进行子查询测试
LeetCode 练习——剑指 Offer 26. 树的子结构
NPDP certification | how do product managers communicate across functions / teams?