Skip to content

Type error when returning JsonObject from Prisma/type-fest when returning from server function #4015

@dccarmo

Description

@dccarmo

Which project does this relate to?

Start

Describe the bug

I have an object being returned from Prisma that accepts JSON as one of the properties (typed as JsonObject from type-fest).

When returning it from a server function, TypeScript gives me this error:

Type 'JsonObject' is not assignable to type 'string | number | boolean | { [x: string]: string | number | boolean | ... | { [x: number]: string | number | boolean | ... | ... | null; length: number; toString: "Function is not serializable"; ... 32 more ...; readonly [Symbol.unscopables]: { ...; }; } | null | undefined; } | { ...; } | null'.

Type 'JsonObject' is missing the following properties from type '{ [x: number]: string | number | boolean | { [x: string]: string | number | boolean | ... | ... | null | undefined; } | ... | null; length: number; toString: "Function is not serializable"; ... 32 more ...; readonly [Symbol.unscopables]: { ...; }; }': length, pop, push, concat, and 29 more.
Image

It seems to me that the handler call from createServerFn expects a JSON value in a specific format that doesn't match what JsonObject is.

Your Example Website or App

https://stackblitz.com/edit/github-ejdg28er?file=src%2Futils%2Fposts.tsx

Steps to Reproduce the Bug or Issue

Return an object that has a property with type JsonObject from type-fest.

Expected behavior

As a user, I'd expect TS to not return any errors (to return the data type in whichever format I need without complaining)

Screenshots or Videos

No response

Platform

  • OS: macOS
  • Browser: Firefox
  • Version: 1.115.2

Additional context

No response

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions