Skip to content

Conversation

@ctonneslan
Copy link

Summary

  • Fixed the TypeScript return type for useCustom hook's result.data property
  • The type now correctly reflects that result.data can be an empty object during loading

Changes

  • Updated UseCustomReturnType in packages/core/src/hooks/data/useCustom.ts
  • Changed data type from CustomResponse<TData>["data"] to CustomResponse<TData>["data"] | Record<string, never>
  • Added changeset documenting the fix

Context

The useCustom hook implementation returns an empty object (EMPTY_OBJECT) for result.data while loading (line 236), but the TypeScript type definition didn't reflect this behavior. This caused TypeScript to not catch potential runtime errors when developers accessed properties on result.data during the loading state.

Example

Before this fix, TypeScript would not error on the following code even though it would fail at runtime during loading:

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

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

// TypeScript thinks someProperty is always defined, but it's not during loading
result.data.someProperty.map(() => console.log);

After this fix, TypeScript will correctly require checking if result.data has the expected properties before accessing them.

Test Plan

  • Verify that TypeScript now requires proper type guards when accessing properties on result.data
  • Verify that existing code using useCustom with proper loading checks continues to work
  • Confirm that the type accurately represents the runtime behavior

Resolves #7088

…ng loading

The useCustom hook returns an empty object for result.data while loading, but the type only indicated it would be CustomResponse<TData>["data"]. This caused TypeScript to not catch potential runtime errors when accessing properties during loading.

Updated return type to include Record<string, never> to accurately represent the empty object state.

Resolves refinedev#7088
@ctonneslan ctonneslan requested a review from a team as a code owner October 27, 2025 13:40
@changeset-bot
Copy link

changeset-bot bot commented Oct 27, 2025

🦋 Changeset detected

Latest commit: ce23f6e

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 1 package
Name Type
@refinedev/core Patch

Not sure what this means? Click here to learn what changesets are.

Click here if you're a maintainer who wants to add another changeset to this PR

@netlify
Copy link

netlify bot commented Oct 27, 2025

Deploy Preview for refine-doc-live-previews ready!

Built without sensitive environment variables

Name Link
🔨 Latest commit ce23f6e
🔍 Latest deploy log https://app.netlify.com/projects/refine-doc-live-previews/deploys/68ff76399690a6000813630e
😎 Deploy Preview https://deploy-preview-7093--refine-doc-live-previews.netlify.app
📱 Preview on mobile
Toggle QR Code...

QR Code

Use your smartphone camera to open QR code link.

To edit notification comments on pull requests, go to your Netlify project configuration.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

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

1 participant