{"id":"a6b7ae6256281500","repo":"sindresorhus/is","slug":"expected-value-which-is-empty-string-or-whitespac","errorCode":null,"errorMessage":"Expected value which is `empty string or whitespace`, received value of type `${is(value)}`.","messagePattern":"Expected value which is `empty string or whitespace`, received value of type `(.+?)`\\.","errorType":"validation","errorClass":"TypeError","httpStatus":null,"severity":"error","filePath":"source/index.ts","lineNumber":1586,"sourceCode":"\t\tthrow new TypeError(message ?? typeErrorMessage('empty object', value));\n\t}\n}\n\nexport function assertEmptySet(value: unknown, message?: string): asserts value is Set<never> {\n\tif (!isEmptySet(value)) {\n\t\tthrow new TypeError(message ?? typeErrorMessage('empty set', value));\n\t}\n}\n\nexport function assertEmptyString(value: unknown, message?: string): asserts value is '' {\n\tif (!isEmptyString(value)) {\n\t\tthrow new TypeError(message ?? typeErrorMessage('empty string', value));\n\t}\n}\n\nexport function assertEmptyStringOrWhitespace(value: unknown, message?: string): asserts value is '' | Whitespace {\n\tif (!isEmptyStringOrWhitespace(value)) {\n\t\tthrow new TypeError(message ?? typeErrorMessage('empty string or whitespace', value));\n\t}\n}\n\nexport function assertEnumCase<T = unknown>(value: unknown, targetEnum: T, message?: string): asserts value is T[keyof T] {\n\tif (!isEnumCase(value, targetEnum)) {\n\t\tthrow new TypeError(message ?? typeErrorMessage('EnumCase', value));\n\t}\n}\n\nexport function assertError(value: unknown, message?: string): asserts value is Error {\n\tif (!isError(value)) {\n\t\tthrow new TypeError(message ?? typeErrorMessage('Error', value));\n\t}\n}\n\nexport function assertEvenInteger(value: number, message?: string): asserts value is number {\n\tif (!isEvenInteger(value)) {\n\t\tthrow new TypeError(message ?? typeErrorMessage('even integer', value));","sourceCodeStart":1568,"sourceCodeEnd":1604,"githubUrl":"https://github.com/sindresorhus/is/blob/7821031c66cdeb7256a0feb2d506535f9e84fcaf/source/index.ts#L1568-L1604","documentation":"Thrown by `assertEmptyStringOrWhitespace` (source/index.ts:1584) when the value is neither the empty string nor a string consisting only of whitespace characters. On success the type narrows to `'' | Whitespace`; any string with non-whitespace content, or any non-string, throws a TypeError with the detected type.","triggerScenarios":"Calling `assert.emptyStringOrWhitespace(value)` with a string containing any non-whitespace character, or with a non-string value (number, null, undefined).","commonSituations":"Validating that an optional text field was left blank; a value that looks blank but contains invisible non-whitespace characters (e.g. zero-width joiners not classified as whitespace); receiving `null` instead of `''` from a form library or database column.","solutions":["Confirm the value is actually a string — null/undefined must be handled before the assertion","If any content is legitimate, replace the assertion with the boolean `is.emptyStringOrWhitespace(value)` and branch","Normalize the input (e.g. `value ?? ''`) upstream if blank should be represented as an empty string"],"exampleFix":"// before\nassert.emptyStringOrWhitespace(null); // non-string, throws\n// after\nassert.emptyStringOrWhitespace(input ?? '');","handlingStrategy":"type-guard","validationCode":"if (typeof value === 'string' && value.trim().length === 0) {\n  assert.emptyStringOrWhitespace(value);\n}","typeGuard":"function isEmptyStringOrWhitespace(value: unknown): value is string {\n  return typeof value === 'string' && value.trim().length === 0;\n}","tryCatchPattern":"try {\n  assert.emptyStringOrWhitespace(value);\n} catch (error) {\n  if (error instanceof TypeError) {\n    // value is non-string or contains non-whitespace characters\n  } else throw error;\n}","preventionTips":["This check requires a string — null/undefined fail it, so guard with typeof first","Use value.trim() === '' as the equivalent inline check","Be aware which whitespace definition applies (String.prototype.trim covers Unicode whitespace)"],"tags":["type-assertion","runtime-validation","string","whitespace","typescript"],"analyzedSha":"7821031c66cdeb7256a0feb2d506535f9e84fcaf","analyzedAt":"2026-07-31T18:34:06.268Z","schemaVersion":2}