Skip to content

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

@MTG2000

Description

@MTG2000

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions