Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Type instantiation is excessively deep and possibly infinite.ts(2589) when using readonly #9776

Closed
punkpeye opened this issue Jul 19, 2024 · 12 comments · Fixed by #9893
Closed

Comments

@punkpeye
Copy link

Reproduction

https://stackblitz.com/edit/remix-run-remix-msgs25?file=app%2Froutes%2F_index.tsx

System Info

N/A

Used Package Manager

pnpm

Expected Behavior

No type error.

Actual Behavior

Getting error:

Type instantiation is excessively deep and possibly infinite.ts(2589)

@punkpeye
Copy link
Author

The only code necessary to replicate is this:

export const loader = defineLoader(async () => {
  type RecentChat = {};

  const recentChats: readonly RecentChat[] = [];

  return {
    recentChats,
  };
});

const Route = () => {
  const data = useLoaderData<typeof loader>();
};

@lilouartz
Copy link

lilouartz commented Aug 2, 2024

@brophdawg11 I am facing the same issue. This is a blocker for adopting turbo-stream. It forces me to continue using json. unstable_data has the same issue.

@lilouartz
Copy link

I dug into types. Looks like fixing this is super simple:

- type Serializable = undefined | null | boolean | string | symbol | number | Array<Serializable> | 
+ type Serializable = undefined | null | boolean | string | symbol | number | Array<Serializable> | ReadonlyArray<Serializable> | 
{
    [key: PropertyKey]: Serializable;
} | bigint | Date | URL | RegExp | Error | Map<Serializable, Serializable> | Set<Serializable> | Promise<Serializable>;

@punkpeye
Copy link
Author

punkpeye commented Aug 6, 2024

This fixed the issue!

@lilouartz
Copy link

@brophdawg11 @jacob-ebey Can this me merged upstream?

At the moment, I have to patch local node_modules every time I update Remix.

@brophdawg11
Copy link
Contributor

defineLoader is going away in favor of a better type story soon so this will be resolved once that lands

@punkpeye
Copy link
Author

defineLoader is going away in favor of a better type story soon so this will be resolved once that lands

That's great news, but apps that currently rely on defineLoader cannot lint properly.

@brophdawg11
Copy link
Contributor

It's an unstable API not intended for production use. // @ts-expect-error is your friend here 😄

@punkpeye punkpeye mentioned this issue Aug 28, 2024
5 tasks
@pcattori pcattori linked a pull request Aug 28, 2024 that will close this issue
5 tasks
@punkpeye
Copy link
Author

What defineLoader and defineAction have been replaced with?

How do I type them?

@0t4u
Copy link

0t4u commented Sep 11, 2024

What defineLoader and defineAction have been replaced with?

How do I type them?

They have been completely removed and not longer required, but the single fetch types need to be enabled, although type inference is broken for me (see #9970).

see: https://github.com/remix-run/remix/blob/main/CHANGELOG.md#improved-single-fetch-type-safety-unstable

@brophdawg11
Copy link
Contributor

This issue has been resolved with 2.12.0 https://stackblitz.com/edit/remix-run-remix-xnwymd

@punkpeye
Copy link
Author

@0t4u see #9969 (comment)

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

Successfully merging a pull request may close this issue.

4 participants