当前位置:网站首页>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;
//}
边栏推荐
- Seata aggregates at, TCC, Saga and XA transaction modes to create a one-stop distributed transaction solution
- The difference between enumeration and define macro
- 第4章:再谈类的加载器
- Heavyweight news | softing fg-200 has obtained China 3C explosion-proof certification to provide safety assurance for customers' on-site testing
- 剪映+json解析将视频中的声音转换成文本
- How do I write Flask's excellent debug log message to a file in production?
- 2022-07-05 使用tpcc对stonedb进行子查询测试
- CocosCreator+TypeScripts自己写一个对象池
- 如何用程序确认当前系统的存储模式?
- 自定义 swap 函数
猜你喜欢
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
二分图判定
0 basic learning C language - interrupt
Aardio - 通过变量名将变量值整合到一串文本中
Improving Multimodal Accuracy Through Modality Pre-training and Attention
Crawler obtains real estate data
[linear algebra] determinant of order 1.3 n
Sword finger offer question brushing record 1
MySQL----初识MySQL
Mysql database basic operations DML
随机推荐
China 1,4-cyclohexanedimethanol (CHDM) industry research and investment decision-making report (2022 Edition)
Unity3d minigame unity webgl transform plug-in converts wechat games to use dlopen, you need to use embedded 's problem
Unity3d minigame-unity-webgl-transform插件转换微信小游戏报错To use dlopen, you need to use Emscripten‘s...问题
网络基础入门理解
云原生技术--- 容器知识点
剪映+json解析将视频中的声音转换成文本
Mise en place d'un environnement de développement OP - tee basé sur qemuv8
2022-07-05 stonedb sub query processing parsing time analysis
labelimg的安装与使用
TypeScript获取函数参数类型
sizeof关键字
MySQL教程的天花板,收藏好,慢慢看
Leetcode: interview question 17.24 Maximum cumulative sum of submatrix (to be studied)
Improving Multimodal Accuracy Through Modality Pre-training and Attention
extern关键字
Senior soft test (Information System Project Manager) high frequency test site: project quality management
What are the specific steps and schedule of IELTS speaking?
MySQL教程的天花板,收藏好,慢慢看
What are the interface tests? What are the general test points?
软考高级(信息系统项目管理师)高频考点:项目质量管理