I have an issue of infering function parameters from generic types.
type CommentServices = {
deleteComment: (commentId: string, parentCommentId?: string) => void;
};
export default function useComments<T extends CommentServices>(CommentServices: T) {
const deleteComment = async (...args: Parameters<T["deleteComment"]>) => {
await CommentServices.deleteComment(...args);
};
}
When passing ...args
to CommentServices.deleteComment
I got this error.
A spread argument must either have a tuple type or be passed to a rest parameter.ts(2556)
Playground.
Playground2 demonstrate why I need genric solution
TypeScript v4.5.4
7