typesafe-formdata
v1.0.1
Published
```ts const formData = new FormData();
Downloads
5
Readme
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');