node-formidable / formidable

The most used, flexible, fast and streaming parser for multipart form data. Supports uploading to serverless environments, AWS S3, Azure, GCP or the filesystem. Used in production.

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

TS Options Type Definition missing createDirsFromUploads

lou-alfaro opened this issue · comments

commented

Support plan

  • Which support plan is this issue covered by? (Community, Sponsor, Enterprise): Community
  • Currently blocking your project/work? (yes/no): no
  • Affecting a production system? (yes/no): no

Context

  • Node.js version: 18.15.0
  • Release Line of Formidable (Legacy, Current, Next): Current
  • Formidable exact version: 3.5.0
  • Environment (node, browser, native, OS): node
  • Used with (popular names of modules): NextJS, TS

What are you trying to achieve or the steps to reproduce?

const form = formidable({
    filename: (_name, _ext, part) => `${Date.now()}/${part.originalFilename}`,
    createDirsFromUploads: true,
});

What was the result you got?

Argument of type '{ filename: (_name: string, _ext: string, part: Part) => string; createDirsFromUploads: boolean; }' is not assignable to parameter of type 'Options'.
  Object literal may only specify known properties, and 'createDirsFromUploads' does not exist in type 'Options'.ts(2345)

What result did you expect?

createDirsFromUploads should exist on type Options in order to be able to override option in a type safe way.

Current Workaround

Type coercion to unknown as follows

const form = formidable({
    filename: (_name, _ext, part) => `${Date.now()}/${part.originalFilename}`,
    createDirsFromUploads: true,
} as unknown);

this silences the ts error without also causing the no-explicit-type-any eslint errors

It looks like this has been fixed by DefinitelyTyped/DefinitelyTyped#66332