Typecheck fails on blog-tutorial example
See original GitHub issueWhen I run typechecking or have my editor open, the following errors are shown by typescript, even on a fresh clone of the example:
> typecheck
> tsc -b && tsc -b cypress
app/routes/notes/$noteId.tsx:36:16 - error TS2352: Conversion of type 'SerializeObject<Simplify<{ note: Note; } & {}>>' to
type 'LoaderData' may be a mistake because neither type sufficiently overlaps with the other. If this was intentional, conv
ert the expression to 'unknown' first.
The types of 'note.createdAt' are incompatible between these types.
Type 'string' is not comparable to type 'Date'.
36 const data = useLoaderData() as LoaderData;
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
app/routes/posts/$slug.tsx:23:26 - error TS2352: Conversion of type 'SerializeObject<Simplify<{ post: Post; html: string; }
& {}>>' to type 'LoaderData' may be a mistake because neither type sufficiently overlaps with the other. If this was inten
tional, convert the expression to 'unknown' first.
The types of 'post.createdAt' are incompatible between these types.
Type 'string' is not comparable to type 'Date'.
23 const { post, html } = useLoaderData() as LoaderData;
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
app/routes/posts/admin.tsx:16:21 - error TS2352: Conversion of type 'SerializeObject<Simplify<{ posts: Post[]; } & {}>>' to
type 'LoaderData' may be a mistake because neither type sufficiently overlaps with the other. If this was intentional, con
vert the expression to 'unknown' first.
Types of property 'posts' are incompatible.
Type 'SerializeObject<Simplify<{ createdAt: Date; updatedAt: Date; title: string; slug: string; markdown: string; } & {
}>>[]' is not comparable to type 'Post[]'.
Type 'SerializeObject<Simplify<{ createdAt: Date; updatedAt: Date; title: string; slug: string; markdown: string; } &
{}>>' is not comparable to type 'Post'.
16 const { posts } = useLoaderData() as LoaderData;
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
app/routes/posts/index.tsx:18:21 - error TS2352: Conversion of type 'SerializeObject<Simplify<{ posts: Post[]; } & {}>>' to
type 'LoaderData' may be a mistake because neither type sufficiently overlaps with the other. If this was intentional, con
vert the expression to 'unknown' first.
Types of property 'posts' are incompatible.
Type 'SerializeObject<Simplify<{ createdAt: Date; updatedAt: Date; title: string; slug: string; markdown: string; } & {
}>>[]' is not comparable to type 'Post[]'.
18 const { posts } = useLoaderData() as LoaderData;
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Found 4 errors.
What seems to be happening is that createdAt
is a string rather than a date somewhere in between (in Prisma, maybe). A temporary workaround is to convert the result of useLoaderData
to unknown
and then LoaderData
, but this isn’t the best solution. This problem happens regardless of the TS version (both 4.7 and 4.8 result in an error). Is there a known solution to this?
Issue Analytics
- State:
- Created a year ago
- Comments:5 (2 by maintainers)
Top Results From Across the Web
Improving TypeScript error handling with exhaustive type ...
Discover an improved method for handling errors in TypeScript that solves problems that arise from returning null and throwing try...catch.
Read more >Introduction to TypeScript type check
Guide to TypeScript type check. Here we discuss the Introduction, syntax, examples with code implementation.
Read more >Typechecking Django and DRF
It will look exactly like the example project. Getting started. In this little tutorial, I will show you several features of django-stubs and ......
Read more >Template type checking
Overview of template type checkinglink. Just as TypeScript catches type errors in your code, Angular checks the expressions and bindings within the ...
Read more >deno - How to activate TypeScript verification of types?
Starting in v 1.23 , by default, Deno does not type-check your code when ... Check file:///Users/deno/example.ts error: TS2322 [ERROR]: Type ...
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
It’s always difficult to keep a tutorial updated with the latest changes (especially on a fast-paced project like Remix).
The “current” recommended approach to typing loaders is as follows:
LoaderArgs
instead ofLoaderFunction
json
helperuseLoaderArgs<typeof loader>()
instead ofas LoaderData
https://github.com/kiliman/remix-typedjson
agree