typescript - 使用来自函数参数的泛型动态类型
问题描述
示例代码
interface E<T extends string> {
operation: T
}
const opt = <T extends string>(op: T) => {
const res: E<op> = someFunc(op)
}
function someFunc<T extends string>(op: T): E<T> {
return {
operation: op
}
}
在这里,我传入op
我的opt
函数,然后调用someFunc
.
错误:
'op' refers to a value, but is being used as a type here. Did you mean 'typeof op'?ts(2749)
我的问题是:
Is it possible to pass a type of generic function as a parameter variable and use?
解决方案
推荐阅读
- android - 改造android中的certificatePinner
- php - 在ajax中使用while循环
- python - 我正在测试 HTTP 获取方法,但出现错误“没有名为 ASCII 的模块”?
- tomcat - 在netbeans问题中盯着tomcat
- javascript - 如何在从 NodeJs 发送的 React js 中捕获响应以检查数据库中是否已存在电子邮件
- powershell - 无论如何让powershell像典型的自动化服务器一样响应ping?
- ios - 找不到 Plugin.h 文件:flutter 和 xcode
- android - RecyclerView 水平布局上的选定项目隐藏在 Android 上的布局开始之后
- bash - 如何传递标志以外的其他参数
- javascript - 如何正确使用 UseCallback Hook