typescript - TypeScript:typeof 泛型类型函数,无需解析为任何或未知
问题描述
我一直在尝试为此寻找解决方案,但我所有的谷歌搜索都没有成功。
我的目标是将泛型类型函数的参数类型提取到一个新的泛型类型中,以便以后使用:
// we have a given function like this:
function genericFunction<T>(a: T) {
return a;
}
type genericParamsType = Parameters<typeof useFormOriginal>; // this will resolve to a type of [unkown]
// I would like to achieve smth like this:
// type genericParamsType<PassDownType> = Parameters<typeof useFormOriginal<PassDownType>>;
// but that is a syntax error
// if it would work, I could the following:
// const newparams: genericParamsType<string> = ["hello"] // correct
// const newparams2: genericParamsType<number> = ["hello"] // error because its not a string
解决方案
推荐阅读
- firebase - 由于 URL 问题,创建新项目以访问旧项目 firestore 数据库
- python - Python将后续列表成员相互添加
- c# - 更改包含 webapi 中多个文件的压缩文件中的数据
- python - 使用 Pip 安装时出错,无法降级 pip
- flutter - 结束动画后运行一个动作
- makefile - 这行“${PROGS} : % : %.o Makefile”在这个 makefile 配方中是什么意思
- django - 如何使用 DRf 中的嵌套序列化程序和视图集同时更新和创建?
- git - 有没有办法将具有特定关键字的 Github 存储库的所有问题/提交提取到 csv 文件?
- python - 我们在 python 中从用户那里获取 int(input()) 的方式,我们不能获取 classname(input())
- grpc-python - 在 Python 中分配类型 google.protobuf.FloatValue 的值