1.0.1 • Published 10 months ago

typesafe-formdata v1.0.1

Weekly downloads
-
License
MIT
Repository
github
Last release
10 months ago

The wrapper around FormData to brind typesafety based on Fluent interface (method chaining).

Problem

const formData = new FormData();

formData.append('one', 'value');

// typechecking just passes without errors
formData.get('two');

Solution

import TypeSafeFormData from 'typesafe-form-data';

const data1 = formData.append('one', 'value');

// TS will throw error that there's no such property
formData.get('two');

const data2 = formData
  .append('one', 'value')
  .delete('one');

// TS will throw error that there's no such property
formData.get('one');

Known issues

Property deletion won't react on a property restoration:

import TypeSafeFormData from 'typesafe-form-data';

const data2 = formData
  .append('one', 'value')
  .delete('one')
  .append('one', 'value');

// TS will throw error that there's no such property
formData.get('one');

A property overwrite will accumulate previous types:

import TypeSafeFormData from 'typesafe-form-data';

const data2 = formData
  .append('one', 'value')
  .set('one', new File([], 'name 2'))

// type will be string | File
const value = formData.get('one');
1.0.1

10 months ago

1.0.0

10 months ago