当前位置:网站首页>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;
//}
边栏推荐
猜你喜欢
Adavit -- dynamic network with adaptive selection of computing structure
每日一题:力扣:225:用队列实现栈
新手程序员该不该背代码?
剪映+json解析将视频中的声音转换成文本
LeetCode 练习——剑指 Offer 26. 树的子结构
金融人士必读书籍系列之六:权益投资(基于cfa考试内容大纲和框架)
[linear algebra] determinant of order 1.3 n
pytorch_YOLOX剪枝【附代码】
MySQL数据库基本操作-DML
Aardio - 利用customPlus库+plus构造一个多按钮组件
随机推荐
MySQL教程的天花板,收藏好,慢慢看
Memorabilia of domestic database in June 2022 - ink Sky Wheel
Inno setup packaging and signing Guide
第3章:类的加载过程(类的生命周期)详解
在IPv6中 链路本地地址的优势
树的先序中序后序遍历
Research and investment strategy report of China's VOCs catalyst industry (2022 Edition)
Web APIs DOM 时间对象
Dealing with the crash of QT quick project in offscreen mode
Pit encountered by handwritten ABA
2022-07-05 使用tpcc对stonedb进行子查询测试
Clip +json parsing converts the sound in the video into text
Windows Auzre 微软的云计算产品的后台操作界面
3DMAX assign face map
【无标题】
关于声子和热输运计算中BORN电荷和non-analytic修正的问题
[linear algebra] determinant of order 1.3 n
SQL Server生成自增序号
二分图判定
TypeScript获取函数参数类型