sor4chi / hono-storage

A storage helper for Hono. Support disk, memory, S3, etc.
MIT License
101 stars 3 forks source link

Example doesn't work anymore #44

Closed k3rne1pan1c closed 3 months ago

k3rne1pan1c commented 4 months ago

Using the following dependencies:

 "dependencies": {
    "@hono-storage/core": "^0.0.9",
    "@hono-storage/node-disk": "^0.0.10",
    "@hono/node-server": "^1.11.1",
    "hono": "^4.3.2"
  },
  "devDependencies": {
    "@types/node": "^20.11.17",
    "tsx": "^4.7.1"
  }

index.ts

import { serve } from "@hono/node-server";
import { HonoDiskStorage } from "@hono-storage/node-disk";
import { Hono } from "hono";

const app = new Hono();
const storage = new HonoDiskStorage({
  dest: "./uploads",
  filename: (_, file) => `${file.originalname}-${Date.now()}.${file.extension}`,
});

app.post("/", storage.single("file"), (c) => c.text("OK"));

serve(app);

Error message over storage.single()

No overload matches this call.
  The last overload gave the following error.
    Argument of type 'MiddlewareHandler<{ Variables: { files: { file?: FieldValue | undefined; }; }; }>' is not assignable to parameter of type 'H<Env, "/", BlankInput, HandlerResponse<any>>'.
      Type 'MiddlewareHandler<{ Variables: { files: { file?: FieldValue | undefined; }; }; }>' is not assignable to type 'MiddlewareHandler<Env, "/", BlankInput>'.
        Types of parameters 'c' and 'c' are incompatible.
          Type 'Context<Env, "/", BlankInput>' is not assignable to type 'Context<{ Variables: { files: { file?: FieldValue | undefined; }; }; }, string, {}>'.
            Property '#private' in type 'Context' refers to a different member that cannot be accessed from within type 'Context'.ts(2769)
types.d.ts(154, 5): The last overload is declared here.

You got an idea, what's wrong?

sor4chi commented 4 months ago

It seems that there is a type discrepancy when using Hono 4 series Hono because they have not updated the Hono version. I’ll patch it the next version, Thank you.