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

FormData type missing File type in get(), getAll() and forEach() #3178

Open
gffuma opened this issue Nov 27, 2024 · 2 comments
Open

FormData type missing File type in get(), getAll() and forEach() #3178

gffuma opened this issue Nov 27, 2024 · 2 comments
Assignees
Labels
types Related to @cloudflare/workers-types

Comments

@gffuma
Copy link

gffuma commented Nov 27, 2024

The FormData type bundled in workers types miss File type in get(), getAll() and forEach() methods and only use string.

Bundled type:

declare class FormData {
  constructor();
  /* [MDN Reference](https://developer.mozilla.org/docs/Web/API/FormData/append) */
  append(name: string, value: string): void;
  /* [MDN Reference](https://developer.mozilla.org/docs/Web/API/FormData/append) */
  append(name: string, value: Blob, filename?: string): void;
  /* [MDN Reference](https://developer.mozilla.org/docs/Web/API/FormData/delete) */
  delete(name: string): void;
  /* [MDN Reference](https://developer.mozilla.org/docs/Web/API/FormData/get) */
  get(name: string): string | null;
  /* [MDN Reference](https://developer.mozilla.org/docs/Web/API/FormData/getAll) */
  getAll(name: string): string[];
  /* [MDN Reference](https://developer.mozilla.org/docs/Web/API/FormData/has) */
  has(name: string): boolean;
  /* [MDN Reference](https://developer.mozilla.org/docs/Web/API/FormData/set) */
  set(name: string, value: string): void;
  /* [MDN Reference](https://developer.mozilla.org/docs/Web/API/FormData/set) */
  set(name: string, value: Blob, filename?: string): void;
  /* Returns an array of key, value pairs for every entry in the list. */
  entries(): IterableIterator<[key: string, value: string]>;
  /* Returns a list of keys in the list. */
  keys(): IterableIterator<string>;
  /* Returns a list of values in the list. */
  values(): IterableIterator<File | string>;
  forEach<This = unknown>(
    callback: (
      this: This,
      value: string,
      key: string,
      parent: FormData,
    ) => void,
    thisArg?: This,
  ): void;
  [Symbol.iterator](): IterableIterator<[key: string, value: string]>;
}

DOM type:

interface FormData {
    /** [MDN Reference](https://developer.mozilla.org/docs/Web/API/FormData/append) */
    append(name: string, value: string | Blob): void;
    append(name: string, value: string): void;
    append(name: string, blobValue: Blob, filename?: string): void;
    /** [MDN Reference](https://developer.mozilla.org/docs/Web/API/FormData/delete) */
    delete(name: string): void;
    /** [MDN Reference](https://developer.mozilla.org/docs/Web/API/FormData/get) */
    get(name: string): FormDataEntryValue | null;
    /** [MDN Reference](https://developer.mozilla.org/docs/Web/API/FormData/getAll) */
    getAll(name: string): FormDataEntryValue[];
    /** [MDN Reference](https://developer.mozilla.org/docs/Web/API/FormData/has) */
    has(name: string): boolean;
    /** [MDN Reference](https://developer.mozilla.org/docs/Web/API/FormData/set) */
    set(name: string, value: string | Blob): void;
    set(name: string, value: string): void;
    set(name: string, blobValue: Blob, filename?: string): void;
    forEach(callbackfn: (value: FormDataEntryValue, key: string, parent: FormData) => void, thisArg?: any): void;
}

Where FormDataEntryValue is:

type FormDataEntryValue = File | string;
@gffuma gffuma added the types Related to @cloudflare/workers-types label Nov 27, 2024
@github-project-automation github-project-automation bot moved this to Untriaged in workers-sdk Nov 27, 2024
@emily-shen
Copy link
Contributor

emily-shen commented Nov 29, 2024

What version of workers-types are you using? Seems to include File on 4.20241106

@Cherry
Copy link
Contributor

Cherry commented Nov 30, 2024

Also note that File support with FormData was only added by the formdata_parser_supports_files compat flag, which became default on 2021-11-03. You will need to make sure you're using @cloudflare/workers-types/2021-11-03 or newer as the default won't include it.

Compare the default:
https://github.com/Cloudflare-Mining/Cloudflare-Datamining/blob/1e63356b12a575e1b061d8ec03abdc160cb77b69/data/workers-types/2021-11-03/index.ts#L1354 - get(name: string): string | null;

vs a newer version: https://github.com/Cloudflare-Mining/Cloudflare-Datamining/blob/main/data/workers-types/2021-11-03/index.ts#L1354 - get(name: string): (File | string) | null;

Make sure you're using @cloudflare/workers-types/2021-11-03 or newer in your tsconfig.json, as per the instructions in the README: https://www.npmjs.com/package/@cloudflare/workers-types

@emily-shen emily-shen moved this from Untriaged to Backlog in workers-sdk Dec 3, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
types Related to @cloudflare/workers-types
Projects
Status: Backlog
Development

No branches or pull requests

4 participants