-
Notifications
You must be signed in to change notification settings - Fork 2.5k
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
Prisma.JsonValue typescript bug after updating to 1.17.0 #6558
Comments
As a work around to stop the typescript error, I'm having to do the following: import type { Example } from '@prisma/client'
//...
export default function RouteComponent() {
const loaderData = useLoaderData<typeof loader>()
const example = loaderData.examples[0] as unknown as Example
return (
<div>
{JSON.stringify(example.json)}
</div>
)
} This sets the type of
EDIT: I understand that the Prisma.JsonValue type is excessively deep and possibly infinite (self referencing), just don't understand why the typescript error appears now and didn't in previous versions of Remix. |
We are seeing the same issue on our end. Interestingly, we don't see the issue when we try to access the data directly, but when we start looping over it, the TS error pops up:
|
Can you reproduce within a Typescript playground? Or provide details on what the |
Example type doesn't seem to matter. Literally did the same as you in my above screenshots (this comment) with: const examples = {} as Prisma.JsonValue[] And I'm still getting the same issue. I'll have a look and see if I can reproduce within a ts playground. |
Here's an example of recursive types working correctly with So not sure why it wouldn't work for Prisma's types 🤷 |
That's the even weirder thing, even though when hovering over the types they look identical (and probably are) in 1.16.1 & 1.17.0. The error only seems to show when using 1.17.0. 😕 |
Here's a sandbox that reproduces the error in the file app/routes/index.tsx :) https://codesandbox.io/p/sandbox/old-architecture-800jum?file=/app/routes/index.tsx The types I created at the top are copy/pasted from the Prisma types. |
Still not able to reproduce in Typescript playground import { json } from '@remix-run/node'
import { useLoaderData } from '@remix-run/react'
interface JsonArray extends Array<JsonValue> {}
type JsonValue = string | number | boolean | JsonObject | JsonArray | null
type JsonObject = { [Key in string]?: JsonValue }
interface Example {
id: string
json: JsonValue
}
export async function loader() {
const examples: Example[] = []
return json({ examples })
}
export default function RouteComponent() {
const loaderData = useLoaderData<typeof loader>()
let ids = loaderData.examples.map((example) => example.id)
// ^? let ids: string[]
} |
Here's a reproduction in Typescript playground. Updated some config settings to match my tsconfig & was able to reproduce the error when trying to access EDIT: Same issue without updating the config. |
Noticed @DerJacques was using an older version of typescript and when using 4.x now the issue is there when looping, but not when accessing json directly, as he initially described. Weird! 😖 |
Thanks for the great repro-case, @dT-Nick! Just wanted to add that I re-used an old sandbox, so that's why the TS version was 4.x. Locally we're using 5.0.4. Very strange that sometimes looping is the issue, while other times accessing the attribute directly is the issue. |
Yeah looks like 5.0.4 and 4.9.5 have the error when looping, but 5.1.3 has the error when accessing it directly. 🤷 |
can you share patch-package file for this fix i want to test it on my workflow, i get this error on 1.17 as well but using prisma includes instead of JSON wonder if it fixes that case too |
I'll put up a PR in a couple hours with this fix |
works |
Thank you very much, @pcattori! Really appreciate your quick turnaround on this one :) |
Fixed by #6582, which will be released in the next release |
🤖 Hello there, We just published version Thanks! |
🤖 Hello there, We just published version Thanks! |
🤖 Hello there, We just published version Thanks! |
🤖 Hello there, We just published version Thanks! |
🤖 Hello there, We just published version Thanks! |
🤖 Hello there, We just published version Thanks! |
What version of Remix are you using?
1.17.0
Are all your remix dependencies & dev-dependencies using the same version?
Steps to Reproduce
Have a prisma schema model that uses the type 'Json' like so:
Get data from that model and return it from a loader, and use
examples
in the route component like so:Expected Behavior
Expecting the type of
loaderData.examples[0].json
to not cause a typescript error, like it didn't before the 1.17.0 update - guessing this is something to do with the new way types are simplified bySerialize
.Actual Behavior
loaderData.examples[0].json
has the following typescript error:Again this worked before 1.17.0, and when downgrading to 1.16.1 the error disappears.
The text was updated successfully, but these errors were encountered: