refine icon indicating copy to clipboard operation
refine copied to clipboard

[BUG] wrong return type of `useOne`

Open gbegher opened this issue 2 years ago • 5 comments

Describe the bug

The type of data in the following code is GetOneResponse<BaseRecord>, but actually it should not be

import { useOne } from "@refinedev/core";
const { data } = useOne();`

Now the typings say that data has another entry with key data inside. This is not true.

Steps To Reproduce

  1. Use useOne
  2. The typing is wrong: ReturnType<typeof useOne<T>>['data'] is T in reality and not GetOneResponse<T> as indicated by the typing

Expected behavior

ReturnType<typeof useOne<T>>['data'] should be T

Packages

  • @refinedev/core

Additional Context

See also another issue, possibly related

gbegher avatar Nov 25 '24 15:11 gbegher

Hey @gbegher thanks for taking time to create issue. GetOneResponse is not wrong, it's correct. However, I understand that having double data data may be confusing. This is something we are improving and will remove in the next major version.

BatuhanW avatar Nov 26 '24 06:11 BatuhanW

Edit: It seems the issue was caused by an incorrect implementation of our data provider.

gbegher avatar Nov 26 '24 08:11 gbegher

@gbegher Can you provide a reproducible example? Because I couldn't reproduce it myself.

Screenshot 2024-11-26 at 11 48 31

Screenshot 2024-11-26 at 11 47 08

BatuhanW avatar Nov 26 '24 08:11 BatuhanW

@BatuhanW Please accept my deepest apologies.

I did a check on our codebase: Our data provider is not implemented correctly and does not return the correct format.

gbegher avatar Nov 26 '24 08:11 gbegher

@gbegher no worries. This is a very confusing return type, and we'll fix it in the next major version.

BatuhanW avatar Nov 26 '24 08:11 BatuhanW