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)
Reproduction
https://stackblitz.com/edit/remix-run-remix-l5e3dj?file=app%2Froutes%2F_index.tsx
System Info
Used Package Manager
npm
Expected Behavior
Expected types to work with a interface/type with arrays, such as the following:
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 justActual Behavior
unstable_defineLoader
accepts types with arrays