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.
MIT License
7k stars 680 forks source link

TS Options Type Definition missing createDirsFromUploads #951

Closed lou-alfaro closed 8 months ago

lou-alfaro commented 11 months ago

Support plan

Context

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

hyperupcall commented 8 months ago

It looks like this has been fixed by https://github.com/DefinitelyTyped/DefinitelyTyped/pull/66332