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

Fix strange Prisma inferred type errors #2099

Open
sodic opened this issue Jun 12, 2024 · 0 comments · May be fixed by #2231
Open

Fix strange Prisma inferred type errors #2099

sodic opened this issue Jun 12, 2024 · 0 comments · May be fixed by #2231
Labels
hm Requires more thought prisma shouldfix We should do/fix this at some point

Comments

@sodic
Copy link
Contributor

sodic commented Jun 12, 2024

Something weird happens when:

  • An operation doesn't explicitly specify its return type (i.e., it relies on type inference)
  • Its return type is a Prisma entity.

More precisely, at some point of our pipeline, the type inferred for the operations API (rpc for the client, wrappers for the server) no longer matches the type inferred at the definition site.

When you fix this, make sure to update the type tests in waspc/todoApp.

Example

I'll explain what's going on on the taskToTaskUnspecified action. You can find it in waspc/todoApp (at the time of writing).

Consider the action defined as:

export const taskToTaskUnspecified = async (args: Task) => args

This is the return type inferred at the definition site:

Promise<GetResult<{
    id: number;
    description: string;
    isDone: boolean;
    userId: number;
}, unknown> & {}>

And this is the return type inferred when I import it from wasp/server/operations or wasp/client/operations:

Promise<GetResult<{
    id: number;
    description: string;
    isDone: boolean;
    userId: number;
}, unknown, never>>

The two types look similar, but they differ in the last type argument.: the original type doesn't specify the last type argument, while the "public" type specifies never.

@sodic sodic added hm Requires more thought prisma shouldfix We should do/fix this at some point labels Jun 12, 2024
@infomiho infomiho linked a pull request Aug 8, 2024 that will close this issue
9 tasks
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
hm Requires more thought prisma shouldfix We should do/fix this at some point
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant