如何从泛型函数中省略prop类型?
declare function func1<T extends {...}>(params: {age: number, something: T, ...more}): string
declare function func2<FunctionType extends (...args: any) => any>(cb: FunctionType): FunctionType
const newFunction = func2(func1) // returns same type as func1
newFunction<{...}>({something: {...}, age: ...}) // is valid, but age should not be valid
在func2
中,如何从FunctionType
的第一个参数中删除属性age
?
我试过:
declare function func2<FunctionType extends (...args: any) => any>(cb: FunctionType):
(params: Omit<Parameters<FunctionType>[0], 'age'>) => ReturnType<FunctionType>
const newFunction = func2(func1) // This returns the new function type without age, but also without generics
newFunction<{...}>({...}) // the generic is no longer valid, bit is should be
这样我就可以删除属性age
,但是返回类型不再是泛型的。我怎样才能保持它的泛型并从第一个参数中省略age
呢?
1条答案
按热度按时间xnifntxz1#
不知道你需要这个通用的,因为你似乎不使用它,但这应该做: