{"id":"93865cfe5eba1f40","repo":"sindresorhus/is","slug":"expected-value-which-is-formdata-received-value","errorCode":null,"errorMessage":"Expected value which is `FormData`, received value of type `${is(value)}`.","messagePattern":"Expected value which is `FormData`, received value of type `(.+?)`\\.","errorType":"validation","errorClass":"TypeError","httpStatus":null,"severity":"error","filePath":"source/index.ts","lineNumber":1634,"sourceCode":"\t\tthrow new TypeError(message ?? typeErrorMessage('finite number', value));\n\t}\n}\n\nexport function assertFloat32Array(value: unknown, message?: string): asserts value is Float32Array {\n\tif (!isFloat32Array(value)) {\n\t\tthrow new TypeError(message ?? typeErrorMessage('Float32Array', value));\n\t}\n}\n\nexport function assertFloat64Array(value: unknown, message?: string): asserts value is Float64Array {\n\tif (!isFloat64Array(value)) {\n\t\tthrow new TypeError(message ?? typeErrorMessage('Float64Array', value));\n\t}\n}\n\nexport function assertFormData(value: unknown, message?: string): asserts value is FormData {\n\tif (!isFormData(value)) {\n\t\tthrow new TypeError(message ?? typeErrorMessage('FormData', value));\n\t}\n}\n\n// eslint-disable-next-line @typescript-eslint/no-unsafe-function-type\nexport function assertFunction(value: unknown, message?: string): asserts value is Function {\n\tif (!isFunction(value)) {\n\t\tthrow new TypeError(message ?? typeErrorMessage('Function', value));\n\t}\n}\n\nexport function assertGenerator(value: unknown, message?: string): asserts value is Generator {\n\tif (!isGenerator(value)) {\n\t\tthrow new TypeError(message ?? typeErrorMessage('Generator', value));\n\t}\n}\n\nexport function assertGeneratorFunction(value: unknown, message?: string): asserts value is GeneratorFunction {\n\tif (!isGeneratorFunction(value)) {","sourceCodeStart":1616,"sourceCodeEnd":1652,"githubUrl":"https://github.com/sindresorhus/is/blob/7821031c66cdeb7256a0feb2d506535f9e84fcaf/source/index.ts#L1616-L1652","documentation":"Thrown by `assertFormData()` when `isFormData()` fails — the value is not an instance of the platform `FormData` class. It guarantees downstream code can safely call FormData methods like `append` and `entries`.","triggerScenarios":"`is.assert.formData(value)` with a plain object of key/value pairs, a URLSearchParams instance, a serialized string, or a polyfilled/third-party form-data object (e.g. the npm `form-data` package in Node) that isn't the global `FormData`.","commonSituations":"Node.js versions before 18 lacking a global FormData; using the `form-data` npm package with fetch wrappers while validation expects the WHATWG FormData; passing `Object.fromEntries(form)` output or raw request bodies instead of the FormData object itself.","solutions":["Construct a real FormData: `const fd = new FormData(); fd.append(...)` or `new FormData(formElement)`.","On Node, ensure Node ≥18 (global WHATWG FormData) or import it from `undici` instead of the legacy `form-data` package.","If the data is a plain object by design, validate with `is.plainObject` and convert to FormData at the network boundary."],"exampleFix":"// before\nconst body = {name: 'x', file};\nassertFormData(body);\n// after\nconst body = new FormData();\nbody.append('name', 'x');\nbody.append('file', file);\nassertFormData(body);","handlingStrategy":"type-guard","validationCode":"if (typeof FormData === 'undefined' || !(value instanceof FormData)) {\n  throw new TypeError('Expected FormData');\n}","typeGuard":"function isFormData(value: unknown): value is FormData {\n  return typeof FormData !== 'undefined' && value instanceof FormData;\n}","tryCatchPattern":"try {\n  assert.formData(value);\n} catch (error) {\n  if (error instanceof TypeError) { /* build a FormData from the plain object instead */ }\n  else throw error;\n}","preventionTips":["Don't pass a plain object of fields where FormData is expected — construct one with `new FormData()` and append entries","In Node < 18 FormData is not global; use undici's FormData or upgrade, and don't mix form-data (npm) instances with native FormData checks","Guard for environment availability (`typeof FormData !== 'undefined'`) in isomorphic code"],"tags":["form-data","type-assertion","runtime-validation","node"],"analyzedSha":"7821031c66cdeb7256a0feb2d506535f9e84fcaf","analyzedAt":"2026-07-31T18:34:06.268Z","schemaVersion":2}