wasp-lang / wasp

The fastest way to develop full-stack web apps with React & Node.js.
https://wasp-lang.dev
MIT License
12.7k stars 1.13k forks source link

Fix strange Prisma inferred type errors #2099

Open sodic opened 2 weeks ago

sodic commented 2 weeks ago

Something weird happens when:

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.