@k1eu/typed-formdata
Version:
A typed version of FormData
29 lines (28 loc) • 1.55 kB
TypeScript
export declare class TypedFormData<T extends Record<string, string | File>> implements FormData {
private formData;
constructor(initElement?: HTMLFormElement | FormData);
get<K extends keyof T>(key: Extract<K, string>): T[K];
getAll(key: string): FormDataEntryValue[];
/**
* Executes a provided function once for each key/value pair in the FormData object.
* @deprecated This method is deprecated and is not advised to be used. Use entries() or for...of loop instead.
* @param callbackfn A function that is called for each key/value pair in the FormData object.
* @param thisArg An object to which the this keyword can refer in the callbackfn function. If thisArg is omitted, undefined is used as the this value.
*/
forEach(callbackfn: (value: FormDataEntryValue, key: string, parent: FormData) => void, thisArg?: unknown): void;
getFormData(): FormData;
getObject(): T;
entries(): IterableIterator<[string, FormDataEntryValue]>;
typedEntries(): IterableIterator<[keyof T, T[keyof T]]>;
keys(): IterableIterator<string>;
values(): IterableIterator<FormDataEntryValue>;
set(key: keyof T, value: T[keyof T]): void;
set(key: string, value: string): void;
set(key: string, value: Blob): void;
append(key: keyof T, value: T[keyof T]): void;
append(key: string, value: string): void;
append(key: string, value: Blob): void;
has(key: string): boolean;
delete(key: string): void;
[Symbol.iterator](): IterableIterator<[string, FormDataEntryValue]>;
}