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?