{"id":"d16aaf0a6318ff21","repo":"sindresorhus/is","slug":"expected-value-which-is-string-with-a-number-re","errorCode":null,"errorMessage":"Expected value which is `string with a number`, received value of type `${is(value)}`.","messagePattern":"Expected value which is `string with a number`, received value of type `(.+?)`\\.","errorType":"validation","errorClass":"TypeError","httpStatus":null,"severity":"error","filePath":"source/index.ts","lineNumber":1811,"sourceCode":"\t}\n}\n\n// eslint-disable-next-line @typescript-eslint/no-restricted-types\nexport function assertNullOrUndefined(value: unknown, message?: string): asserts value is null | undefined {\n\tif (!isNullOrUndefined(value)) {\n\t\tthrow new TypeError(message ?? typeErrorMessage('null or undefined', value));\n\t}\n}\n\nexport function assertNumber(value: unknown, message?: string): asserts value is number {\n\tif (!isNumber(value)) {\n\t\tthrow new TypeError(message ?? typeErrorMessage('number', value));\n\t}\n}\n\nexport function assertNumericString(value: unknown, message?: string): asserts value is `${number}` {\n\tif (!isNumericString(value)) {\n\t\tthrow new TypeError(message ?? typeErrorMessage('string with a number', value));\n\t}\n}\n\n// eslint-disable-next-line @typescript-eslint/no-restricted-types\nexport function assertObject(value: unknown, message?: string): asserts value is object {\n\tif (!isObject(value)) {\n\t\tthrow new TypeError(message ?? typeErrorMessage('Object', value));\n\t}\n}\n\nexport function assertObservable(value: unknown, message?: string): asserts value is ObservableLike {\n\tif (!isObservable(value)) {\n\t\tthrow new TypeError(message ?? typeErrorMessage('Observable', value));\n\t}\n}\n\nexport function assertOddInteger(value: number, message?: string): asserts value is number {\n\tif (!isOddInteger(value)) {","sourceCodeStart":1793,"sourceCodeEnd":1829,"githubUrl":"https://github.com/sindresorhus/is/blob/7821031c66cdeb7256a0feb2d506535f9e84fcaf/source/index.ts#L1793-L1829","documentation":"Thrown by `assert.numericString()` when the value is not a string containing a valid number. `isNumericString` requires the value to be a string whose contents parse as a number (template-literal type `${number}`); non-strings and non-numeric strings both fail. Actual numbers also fail — the check is specifically for the string representation.","triggerScenarios":"Calling `assert.numericString(value)` with an actual number (e.g. 42), an empty string, a string with units ('42px'), whitespace-padded or comma-formatted numbers ('1,000'), null, or undefined.","commonSituations":"Validating URL path/query parameters or HTTP headers expected to carry numeric IDs; CSV cell values with stray whitespace or thousands separators; passing an already-parsed number where the raw string was expected.","solutions":["If the value is already a number, use `assert.number()` instead — numericString requires a string.","Sanitize the input first: `value.trim()` and strip formatting characters before asserting.","Trace where the empty/malformed string originates (missing query param defaults to '') and fail earlier with a clearer message.","Pass a custom message as the second argument to identify which field failed."],"exampleFix":"// before\nassert.numericString(42); // throws: received 'number'\n// after\nassert.numericString('42');\n// or, for numbers:\nassert.number(42);","handlingStrategy":"validation","validationCode":"if (typeof value !== 'string' || value.trim() === '' || Number.isNaN(Number(value))) {\n  throw new TypeError(`Expected numeric string, got ${JSON.stringify(value)}`);\n}","typeGuard":"function isNumericString(value: unknown): value is string {\n  return typeof value === 'string' && value.trim() !== '' && !Number.isNaN(Number(value));\n}","tryCatchPattern":"try {\n  ow(value, ow.string.numeric);\n} catch (error) {\n  if (error instanceof ArgumentError) {\n    throw new TypeError(`Expected a string containing a number: ${error.message}`);\n  }\n  throw error;\n}","preventionTips":["Validate query params and form fields (always strings) with a numeric-string check at the trust boundary","Beware Number('') === 0 — reject empty/whitespace strings explicitly","Don't pass actual numbers where a numeric string is expected; call String(n) deliberately","Normalize locale formats (commas, thousands separators) before validation"],"tags":["type-check","assertion","string-validation","runtime-validation"],"analyzedSha":"7821031c66cdeb7256a0feb2d506535f9e84fcaf","analyzedAt":"2026-07-31T18:34:06.268Z","schemaVersion":2}