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

useSWR with optimisticData - Typescript error

$
0
0

I am using the new optimisticData feature of useSWR as follows:

const { data, error, isLoading, mutate } = useSWR<IUser | undefined>(`/api/user`, () => apiClient.user.userGet())

and further down in a function I try to mutate the user data:

 mutate(     apiClient.user.userUpdate({         userUpdateRequest: {               name: value,         }     }),     {          optimisticData: {          ...data,          name: value,     },          populateCache: false,     } )

apiClient.user.userUpdate is a function generated by openapi and has this signature:

/** * Update user fields */async userUpdate(requestParameters: UserUpdateOperationRequest = {}, initOverrides?: RequestInit | runtime.InitOverrideFunction): Promise<void> {    await this.userUpdateRaw(requestParameters, initOverrides);}

Although the code works fine, it does generate the following Typescript error which I cannot get rid of:

Argument of type 'Promise' is not assignable to parameter of type 'IUser | Promise<IUser | undefined> | MutatorCallback<IUser | undefined> | undefined'.Type 'Promise' is not assignable to type 'Promise<IUser | undefined>'.Type 'void' is not assignable to type 'IUser | undefined'.

We are using ReactNative. Any ideas?


Viewing all articles
Browse latest Browse all 6290

Trending Articles



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