We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
I'm using the Typescript RTK Query code gen plugin to generate some api hooks.
Example:
const injectedRtkApi = api.injectEndpoints({ overrideExisting: true, endpoints: (build) => ({ Notification: build.query<NotificationQuery, NotificationQueryVariables>({ query: (variables) => ({ document: NotificationDocument, variables }) }), }), }); export { injectedRtkApi as api }; export const { useNotificationQuery, useLazyNotificationQuery } = injectedRtkApi;
I'd like to use enhanceEndpoints to return one of the nested values in the query result:
enhanceEndpoints
import { api, NotificationQuery, } from './Notification.generated'; export const {useNotificationQuery} = api.enhanceEndpoints({ endpoints: { Notification: { transformResponse: (result: NotificationQuery) => result.notificationByNotificationId } }});
When I do this, TypeScript throws the following error, which I interpret as it expecting transformResponse to be undefined:
transformResponse
undefined
TS2322: Type '(result: NotificationQuery) => { __typename?: "Notification" | undefined; id: string; }' is not assignable to type 'undefined'.
I also tried using the definition:
export const {useNotificationQuery} = api.enhanceEndpoints({ endpoints: { Notification(definition) { definition.transformResponse: (result: NotificationQuery) => result.notificationByNotificationId } }});
Which is happier but suggests that NotificationQuery['notificationByNotificationId'] is not assignable to NotificationQuery.
NotificationQuery['notificationByNotificationId']
NotificationQuery
Where I use the hook, it also still thinks that data is NotificationQuery and not NotificationQuery['notificationByNotificationId'].
data
This has my head scratching as there aren't any examples I could find of overriding the ResultType.
I'm using TypeScript 4.4.4 and RTK 1.8.1.
The text was updated successfully, but these errors were encountered:
Probably the same as #1441
Sorry, something went wrong.
No branches or pull requests
I'm using the Typescript RTK Query code gen plugin to generate some api hooks.
Example:
I'd like to use
enhanceEndpoints
to return one of the nested values in the query result:When I do this, TypeScript throws the following error, which I interpret as it expecting
transformResponse
to beundefined
:I also tried using the definition:
Which is happier but suggests that
NotificationQuery['notificationByNotificationId']
is not assignable toNotificationQuery
.Where I use the hook, it also still thinks that
data
isNotificationQuery
and notNotificationQuery['notificationByNotificationId']
.This has my head scratching as there aren't any examples I could find of overriding the ResultType.
I'm using TypeScript 4.4.4 and RTK 1.8.1.
The text was updated successfully, but these errors were encountered: