Quantcast
Channel: Active questions tagged react-native+typescript - Stack Overflow
Viewing all articles
Browse latest Browse all 6290

Typescript gives following error for adding a return type for query in RTK query

$
0
0

My code is as beloew

interface CurriculumDetailsApi {  curriculum_id: number;  curriculum_name: string;  description: string;  percentage_of_completion: number;  post_id: string;  post_type: string;  topics: Topics[];}const apiWithTaggedEndpoints = apiWithTag.injectEndpoints({  endpoints: builder => ({    curriculumDetails: builder.query<CurriculumDetailsApi, input>({      query: payload => ({        url: `/${payload.postId}/${payload.employeeId}`,        method: 'GET',        headers: {'Content-Type': 'application/json',        },      }),    }),  }),  overrideExisting: true,> });

I get an error like this

Type '(payload: Args) => { url: string; method: string; headers: { 'Content-Type': string; }; }' is not assignable to type '(arg: Args) => string'.Type '{ url: string; method: string; headers: { 'Content-Type': string; }; }' is not assignable to type 'string'.ts(2322)endpointDefinitions.d.ts(36, 5): The expected type comes from property 'query' which is declared here on type 'Omit<EndpointDefinitionWithQuery<Args, BaseQueryFn<string, unknown, { reason: string; }, { shout?: boolean | undefined; }, { timestamp: number; }>, CurriculumDetailsApi> & { ...; } & { ...; } & QueryExtraOptions<...>, "type"> | Omit<...>'

How can i assign type to the data from the API call


Viewing all articles
Browse latest Browse all 6290

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>