Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/wix/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
TypeScript:泛型类型函数的类型,不解析为任何类型或未知类型_Typescript_Types_Typescript Generics - Fatal编程技术网

TypeScript:泛型类型函数的类型,不解析为任何类型或未知类型

TypeScript:泛型类型函数的类型,不解析为任何类型或未知类型,typescript,types,typescript-generics,Typescript,Types,Typescript Generics,我一直在寻找解决方案,但我所有的谷歌搜索都没有成功 我的目标是将泛型函数的参数类型提取到一个新的泛型类型中,以便以后使用: // we have a given function like this: function genericFunction<T>(a: T) { return a; } type genericParamsType = Parameters<typeof useFormOriginal>; // this will resolve to a

我一直在寻找解决方案,但我所有的谷歌搜索都没有成功

我的目标是将泛型函数的参数类型提取到一个新的泛型类型中,以便以后使用:

// 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
//我们有这样一个给定的函数:
函数泛型函数(a:T){
返回a;
}
类型genericParamsType=参数;//这将解析为一种[未知的]
//我希望通过以下方式实现smth:
//类型genericParamsType=参数;
//但这是一个语法错误
//如果可行,我可以做以下几点:
//const newparams:genericParamsType=[“hello”]//正确
//const newparams2:genericParamsType=[“hello”]//错误,因为它不是字符串

您的解决方案需要多大的灵活性?仅此特定功能?任何带有一个泛型参数的函数?有多少通用参数?您的解决方案需要多大的灵活性?仅此特定功能?任何带有一个泛型参数的函数?有多少通用参数?