Skip to content
Source
Sign inSign up
TanStack/router

Returning objects with type `unknown` in `beforeLoad`/`loader` started throwing error after v1.132.x #5222

Send to my agent
ClosedMTG2000(GitHub profile, opens in a new tab) opened this issue 3 comments

Which project does this relate to?

Router

Describe the bug

In earlier versions it was okay to return an object with a type that contains unknown for one of its properties like:

type TypeWithUnknown = {
  value: unknown;
};

export const Route = createFileRoute('/_layout')({
  component: RouteComponent,
  beforeLoad() {
    const obj = { value: {} } as TypeWithUnknown;

    return { obj };
  },
  loader: async ({ context }) => {
    return context.obj.value;
  },
});

But after updating to version 1.132.6, the above code throws this error:

Call signature return types '{ obj: TypeWithUnknown; }' and '{ obj: { value: {}; }; }' are incompatible.
    The types of 'obj.value' are incompatible between these types.
      Type 'unknown' is not assignable to type '{}'.

Your Example Website or App

https://stackblitz.com/edit/github-51knrjza-rwsunnqu?file=src%2Froutes%2F_layout.tsx

Steps to Reproduce the Bug or Issue

Go to the _layout file in the code repo above and you should see the errors on beforeLoader and loader

Expected behavior

I believe this is a bug and the behaviour should remain consistent with what it was in earlier versions.

Screenshots or Videos

No response

Platform

  • Router Version: [e.g. 1.132.6]
  • OS: Linux
  • Browser: Chrome

Additional context

No response

  1. This issue is still present on version 1.139.12

  2. @dominikjasek in router or in start? in start it is expected as unknown could mean not serializable

  3. @dominikjasek in router or in start? in start it is expected as unknown could mean not serializable

    Yep. Its start. 👌

Sign in to join this conversation.