当前位置:网站首页>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;
//}边栏推荐
- MySQL约束的分类、作用及用法
- 12、 Start process
- Mise en place d'un environnement de développement OP - tee basé sur qemuv8
- Clip +json parsing converts the sound in the video into text
- Plafond du tutoriel MySQL, bien collecté, regardez lentement
- 0 basic learning C language - digital tube
- 自定义 swap 函数
- UDP编程
- Leetcode exercise - Sword finger offer 26 Substructure of tree
- MySQL ---- first acquaintance with MySQL
猜你喜欢
![[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

软考高级(信息系统项目管理师)高频考点:项目质量管理

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

Data processing skills (7): MATLAB reads the data in the text file TXT with mixed digital strings

2022-07-04 the high-performance database engine stonedb of MySQL is compiled and run in centos7.9

rust知识思维导图xmind

Attack and defense world miscall

Aardio - 封装库时批量处理属性与回调函数的方法

Netxpert xg2 helps you solve the problem of "Cabling installation and maintenance"
The SQL response is slow. What are your troubleshooting ideas?
随机推荐
Comparison between variable and "zero value"
SQL Server生成自增序号
2022-07-04 the high-performance database engine stonedb of MySQL is compiled and run in centos7.9
Config:invalid signature solution and troubleshooting details
Adavit -- dynamic network with adaptive selection of computing structure
Daily question 1: force deduction: 225: realize stack with queue
How big is the empty structure?
Senior soft test (Information System Project Manager) high frequency test site: project quality management
LeetCode 练习——剑指 Offer 26. 树的子结构
NPDP certification | how do product managers communicate across functions / teams?
Aardio - 通过变量名将变量值整合到一串文本中
What are the interface tests? What are the general test points?
HDR image reconstruction from a single exposure using deep CNN reading notes
做接口测试都测什么?有哪些通用测试点?
如何实现文字动画效果
Report on technological progress and development prospects of solid oxide fuel cells in China (2022 Edition)
(18) LCD1602 experiment
金融人士必读书籍系列之六:权益投资(基于cfa考试内容大纲和框架)
Const keyword
Data storage (1)