当前位置:网站首页>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;
//}
边栏推荐
- 基于 QEMUv8 搭建 OP-TEE 开发环境
- 软考高级(信息系统项目管理师)高频考点:项目质量管理
- Applet system update prompt, and force the applet to restart and use the new version
- poj 1094 Sorting It All Out (拓扑排序)
- Signed and unsigned keywords
- Chapter 4: talk about class loader again
- const关键字
- three.js绚烂的气泡效果
- 3DMAX assign face map
- Pit encountered by handwritten ABA
猜你喜欢
C# 三种方式实现Socket数据接收
自制J-Flash烧录工具——Qt调用jlinkARM.dll方式
Aardio - 利用customPlus库+plus构造一个多按钮组件
Attack and defense world ditf Misc
Self made j-flash burning tool -- QT calls jlinkarm DLL mode
基於 QEMUv8 搭建 OP-TEE 開發環境
机试刷题1
RESNET rs: Google takes the lead in tuning RESNET, and its performance comprehensively surpasses efficientnet series | 2021 arXiv
Unity3d minigame-unity-webgl-transform插件转换微信小游戏报错To use dlopen, you need to use Emscripten‘s...问题
如何用程序确认当前系统的存储模式?
随机推荐
Attack and defense world ditf Misc
Clip +json parsing converts the sound in the video into text
每日一题:力扣:225:用队列实现栈
Puppeteer连接已有Chrome浏览器
Config:invalid signature solution and troubleshooting details
3DMAX assign face map
What are the specific steps and schedule of IELTS speaking?
金融人士必读书籍系列之六:权益投资(基于cfa考试内容大纲和框架)
Aardio - 利用customPlus库+plus构造一个多按钮组件
rust知识思维导图xmind
Leetcode question brushing (XI) -- sequential questions brushing 51 to 55
Mise en place d'un environnement de développement OP - tee basé sur qemuv8
Signed and unsigned keywords
Const keyword
Export MySQL table data in pure mode
The nearest common ancestor of binary (search) tree ●●
项目复盘模板
Sizeof keyword
poj 1094 Sorting It All Out (拓扑排序)
Leetcode: interview question 17.24 Maximum cumulative sum of submatrix (to be studied)