diff --git a/src/createUseMutation.ts b/src/createUseMutation.ts index 247a80f..71832c2 100644 --- a/src/createUseMutation.ts +++ b/src/createUseMutation.ts @@ -28,7 +28,7 @@ export const createUseMutation = ( const responseDataType = ts.factory.createTypeParameterDeclaration( undefined, - "ResponseData", + "TData", undefined, awaitedResponseDataType ); @@ -61,7 +61,21 @@ export const createUseMutation = ( undefined, ts.factory.createArrowFunction( undefined, - ts.factory.createNodeArray([responseDataType]), + ts.factory.createNodeArray([ + responseDataType, + ts.factory.createTypeParameterDeclaration( + undefined, + "TError", + undefined, + ts.factory.createKeywordTypeNode(ts.SyntaxKind.UnknownKeyword) + ), + ts.factory.createTypeParameterDeclaration( + undefined, + "TContext", + undefined, + ts.factory.createKeywordTypeNode(ts.SyntaxKind.UnknownKeyword) + ), + ]), [ ts.factory.createParameterDeclaration( undefined, @@ -152,7 +166,7 @@ export const createUseMutation = ( ]), ] ), - // Omit, 'data'> & { data: ResponseData }; + // Omit>, TError, params, TContext>, 'data'> & { data: TData }; ts.factory.createIntersectionTypeNode([ ts.factory.createTypeReferenceNode( ts.factory.createIdentifier("Omit"), @@ -161,12 +175,14 @@ export const createUseMutation = ( ts.factory.createIdentifier("UseMutationResult"), [ awaitedResponseDataType, - ts.factory.createKeywordTypeNode( - ts.SyntaxKind.UnknownKeyword + ts.factory.createTypeReferenceNode( + ts.factory.createIdentifier("TError"), + undefined ), methodParameters, - ts.factory.createKeywordTypeNode( - ts.SyntaxKind.UnknownKeyword + ts.factory.createTypeReferenceNode( + ts.factory.createIdentifier("TContext"), + undefined ), ] ), @@ -181,7 +197,7 @@ export const createUseMutation = ( ts.factory.createIdentifier("data"), undefined, ts.factory.createTypeReferenceNode( - ts.factory.createIdentifier("ResponseData"), + ts.factory.createIdentifier("TData"), undefined ) ), diff --git a/src/createUseQuery.ts b/src/createUseQuery.ts index b80cdba..8266cfc 100644 --- a/src/createUseQuery.ts +++ b/src/createUseQuery.ts @@ -72,7 +72,7 @@ export const createUseQuery = ( const responseDataType = ts.factory.createTypeParameterDeclaration( undefined, - "ResponseData", + "TData", undefined, awaitedResponseDataType ); @@ -118,6 +118,14 @@ export const createUseQuery = ( ) ), responseDataType, + ts.factory.createTypeParameterDeclaration( + undefined, + "TError", + undefined, + ts.factory.createKeywordTypeNode( + ts.SyntaxKind.UnknownKeyword + ) + ), ]), [ ...requestParam, @@ -236,7 +244,7 @@ export const createUseQuery = ( ]), ] ), - // Omit, 'data'> & { data: ResponseData }; + // Omit>, TError>, 'data'> & { data: TData }; ts.factory.createIntersectionTypeNode([ ts.factory.createTypeReferenceNode( ts.factory.createIdentifier("Omit"), @@ -245,8 +253,9 @@ export const createUseQuery = ( ts.factory.createIdentifier("UseQueryResult"), [ awaitedResponseDataType, - ts.factory.createKeywordTypeNode( - ts.SyntaxKind.UnknownKeyword + ts.factory.createTypeReferenceNode( + ts.factory.createIdentifier("TError"), + undefined ), ] ), @@ -261,7 +270,7 @@ export const createUseQuery = ( ts.factory.createIdentifier("data"), undefined, ts.factory.createTypeReferenceNode( - ts.factory.createIdentifier("ResponseData"), + ts.factory.createIdentifier("TData"), undefined ) ),