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

unstable_defineLoader can't handle types with arrays #9527

Closed
brookslybrand opened this issue May 30, 2024 · 3 comments
Closed

unstable_defineLoader can't handle types with arrays #9527

brookslybrand opened this issue May 30, 2024 · 3 comments
Assignees
Labels
bug Something isn't working feat:single-fetch

Comments

@brookslybrand
Copy link
Contributor

Reproduction

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

System Info

System:
    OS: Linux 5.0 undefined
    CPU: (8) x64 Intel(R) Core(TM) i9-9880H CPU @ 2.30GHz
    Memory: 0 Bytes / 0 Bytes
    Shell: 1.0 - /bin/jsh
  Binaries:
    Node: 18.20.3 - /usr/local/bin/node
    Yarn: 1.22.19 - /usr/local/bin/yarn
    npm: 10.2.3 - /usr/local/bin/npm
    pnpm: 8.15.6 - /usr/local/bin/pnpm
  npmPackages:
    @remix-run/dev: * => 2.9.2 
    @remix-run/node: * => 2.9.2 
    @remix-run/react: * => 2.9.2 
    @remix-run/serve: * => 2.9.2 
    vite: ^5.1.0 => 5.2.12

Used Package Manager

npm

Expected Behavior

Expected types to work with a interface/type with arrays, such as the following:

interface BlogPost {
  title: string;
  authors: { name: string }[];
}

async function getBlogPost(): Promise<BlogPost> {
  return Promise.resolve({
    title: 'example blog',
    authors: [{ name: 'brooks' }], // This seems to be the problem
  });
}

export const loader = defineLoader(async () => {
  const blog = await getBlogPost();
  return { blog };
});

If you update getBlogPost to infer it's return type, everything works. However, this is not ideal, since that might require changing a lot of types, plus some people don't want their functions to infer types, they'd rather declare the return type.

Additionally, the type error message is pretty dense. For useLoader, the message is just

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

Actual Behavior

unstable_defineLoader accepts types with arrays

@brookslybrand
Copy link
Contributor Author

@pcattori here's a screenshot of the type error this gives me

image

@KubaJastrz
Copy link

KubaJastrz commented May 30, 2024

Duplicate of #9514

@brookslybrand
Copy link
Contributor Author

Thanks @KubaJastrz, closing in favor of your issue

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working feat:single-fetch
Projects
None yet
Development

No branches or pull requests

3 participants