Skip to content

[BUG] useCustom return type is incorrect and undocumented v5 breaking change #7088

@TomCaserta

Description

@TomCaserta

Describe the bug

Since this commit:
https://github.com/refinedev/refine/blame/3bb1d1ea3ba72f6ca24a703ccef88de29a1782f3/packages/core/src/hooks/data/useCustom.ts#L234

useCustom always returns an object for result.data. This is seems to be an undocumented breaking change as any code relying on data being null/undefined while loading will break.

Additionally, the typings are seemingly incorrect.

export type UseCustomReturnType<TData, TError> = {
  query: QueryObserverResult<CustomResponse<TData>, TError>;
  result: {
    data: CustomResponse<TData>["data"];
  };
} & UseLoadingOvertimeReturnType;

While data is always defined now, the type is incorrect because data is an empty object while loading and not CustomResponse<TData>["data"]

This means any errors because of this is completely invisible until you actually run the code

Steps To Reproduce

type MyCustomData = {
    id: string;
    someProperty: number[];
};

const { result } = useCustom<MyCustomData>({ url: 'something', method: 'get' });

result.data.someProperty.map(() => console.log);

Expected behavior

I expect a type error because result.data.someProperty could be undefined.

Additional Context

No response

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions