当前位置:网站首页>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 anyTranslate 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;
//}边栏推荐
- Installation and use of labelimg
- MySQL教程的天花板,收藏好,慢慢看
- Hardware development notes (10): basic process of hardware development, making a USB to RS232 module (9): create ch340g/max232 package library sop-16 and associate principle primitive devices
- Chapter 4: talk about class loader again
- Leetcode exercise - Sword finger offer 26 Substructure of tree
- Self made j-flash burning tool -- QT calls jlinkarm DLL mode
- Applet system update prompt, and force the applet to restart and use the new version
- Report on technological progress and development prospects of solid oxide fuel cells in China (2022 Edition)
- 新手程序员该不该背代码?
- How to confirm the storage mode of the current system by program?
猜你喜欢

如何用程序确认当前系统的存储模式?

Netxpert xg2 helps you solve the problem of "Cabling installation and maintenance"

Seata aggregates at, TCC, Saga and XA transaction modes to create a one-stop distributed transaction solution

config:invalid signature 解决办法和问题排查详解

基於 QEMUv8 搭建 OP-TEE 開發環境
![[Digital IC hand tearing code] Verilog burr free clock switching circuit | topic | principle | design | simulation](/img/2b/15b3d831bba6aa772ad83f3ac91d23.png)
[Digital IC hand tearing code] Verilog burr free clock switching circuit | topic | principle | design | simulation

0 basic learning C language - interrupt

金融人士必读书籍系列之六:权益投资(基于cfa考试内容大纲和框架)

基于 QEMUv8 搭建 OP-TEE 开发环境

Crawler obtains real estate data
随机推荐
项目复盘模板
Seata aggregates at, TCC, Saga and XA transaction modes to create a one-stop distributed transaction solution
npm无法安装sharp
memcached
如何实现文字动画效果
Crawler obtains real estate data
LeetCode 练习——剑指 Offer 26. 树的子结构
2022-07-05 use TPCC to conduct sub query test on stonedb
Should novice programmers memorize code?
leetcode:面试题 17.24. 子矩阵最大累加和(待研究)
MySQL约束的分类、作用及用法
Puppeteer连接已有Chrome浏览器
go多样化定时任务通用实现与封装
uniapp滑动到一定的高度后固定某个元素到顶部效果demo(整理)
剪映+json解析将视频中的声音转换成文本
2022-07-04 mysql的高性能数据库引擎stonedb在centos7.9编译及运行
【雅思口语】安娜口语学习记录part1
How big is the empty structure?
signed、unsigned关键字
Signed and unsigned keywords