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

[bug]: file router object array input types #1141

Open
2 tasks done
marier-nico opened this issue Feb 1, 2025 · 0 comments
Open
2 tasks done

[bug]: file router object array input types #1141

marier-nico opened this issue Feb 1, 2025 · 0 comments
Labels
area:packages issue regarding one of the uploadthing packages 🐛 bug: unconfirmed

Comments

@marier-nico
Copy link

Provide environment information

System:
    OS: macOS 15.1.1
    CPU: (8) arm64 Apple M1 Pro
    Memory: 89.81 MB / 16.00 GB
    Shell: 3.7.1 - /opt/homebrew/bin/fish
  Binaries:
    Node: 20.12.0 - ~/.volta/tools/image/node/20.12.0/bin/node
    Yarn: 4.0.0-rc.42 - ~/.volta/tools/image/yarn/4.0.0-rc.42/bin/yarn
    npm: 10.5.0 - ~/.volta/tools/image/node/20.12.0/bin/npm
    pnpm: 9.5.0 - ~/.volta/bin/pnpm
    bun: 1.1.15 - ~/.volta/bin/bun
  Browsers:
    Chrome: 132.0.6834.160
    Safari: 18.1.1
  npmPackages:
    @uploadthing/react: ^7.1.5 => 7.1.5
    typescript: ^5.5.3 => 5.7.3
    uploadthing: ^7.4.4 => 7.4.4

Describe the bug

The following typescript error occurs when trying to use an array of objects in the input of a file router

    Types of property '_input' are incompatible.
      Type '{ media: { id: string; }[]; }' is not assignable to type 'Json'.
        Type '{ media: { id: string; }[]; }' is not assignable to type 'JsonObject'.
          Property 'media' is incompatible with index signature.
            Type '{ id: string; }[]' is not assignable to type 'JsonValue | JsonObject | JsonArray'.
              Type '{ id: string; }[]' is not assignable to type 'JsonArray'.
                Type '{ id: string; }' is not assignable to type 'JsonValue'.

The documentation only highlights that the input must be JSON serializable, which it is, so this feels like the internal json type isn't quite right. If it's intentional, it'd be helpful to mention it in the docs.

Link to reproduction

https://stackblitz.com/edit/github-uvnavyz9?file=src%2Fserver%2Fuploadthing.ts&view=editor

To reproduce

Check src/server/uploadthing.ts (line 40) in the reproduction link. When the sandbox loads, you can see the type error.

And just to have it here also, this input schema gives the error : const imageSchema = z.object({ media: z.array(z.object({ id: z.string() })) });

Additional information

It feels like the fix might just be to change these types in @uploadthing/shared, but in any case I wanted to file this to make sure I didn't miss anything 👀

type JsonValue = string | number | boolean | null | undefined;
type JsonArray = JsonValue[]; // --> use Json[] instead?
type JsonObject = {
    [key: string]: JsonValue | JsonObject | JsonArray; // --> maybe here too
};
type Json = JsonValue | JsonObject | JsonArray;

👨‍👧‍👦 Contributing

  • 🙋‍♂️ Yes, I'd be down to file a PR fixing this bug!

Code of Conduct

  • I agree to follow this project's Code of Conduct
@marier-nico marier-nico added area:packages issue regarding one of the uploadthing packages 🐛 bug: unconfirmed labels Feb 1, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area:packages issue regarding one of the uploadthing packages 🐛 bug: unconfirmed
Projects
None yet
Development

No branches or pull requests

1 participant