Skip to content

TypeScript type definitions for Blob, File, FormData #1150

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

Merged
merged 1 commit into from
Mar 13, 2025

Conversation

harmony7
Copy link
Member

This PR adds TypeScript typings for Blob, File, and FormData so they can be used in Compute apps in TypeScript.

Now tsc is happy with all this:

  if (event.request.headers.get('content-type')?.startsWith('multipart/form-data')) {
    const reqFormData = await event.request.formData();
    reqFormData.forEach((value, key) => {
      console.log(key, value);
    });
  }

  const file = new File(['hello, world'], 'temp.txt', {
    type: 'text/plain'
  });

  const formData = new FormData();
  formData.set('foo', '0');
  formData.set('bar', 'doo');
  formData.set('baz', file);

  const resp = await fetch(
    'https://httpbin.org/anything', {
      method: 'POST',
      body: formData,
      backend: 'httpbin',
    },
  );

@harmony7 harmony7 requested a review from guybedford March 13, 2025 06:55
@guybedford guybedford merged commit 4c93d79 into main Mar 13, 2025
22 of 28 checks passed
@guybedford guybedford deleted the kats/types-blob-file-formdata branch March 13, 2025 16:11
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants