{"id":"0e7f3821731b0770","repo":"sindresorhus/is","slug":"expected-value-which-is-date-received-value-of","errorCode":null,"errorMessage":"Expected value which is `Date`, received value of type `${is(value)}`.","messagePattern":"Expected value which is `Date`, received value of type `(.+?)`\\.","errorType":"validation","errorClass":"TypeError","httpStatus":null,"severity":"error","filePath":"source/index.ts","lineNumber":1544,"sourceCode":"\t\tthrow new TypeError(message ?? typeErrorMessage('Buffer', value));\n\t}\n}\n\nexport function assertClass<T>(value: unknown, message?: string): asserts value is Class<T> {\n\tif (!isClass(value)) {\n\t\tthrow new TypeError(message ?? typeErrorMessage('Class', value));\n\t}\n}\n\nexport function assertDataView(value: unknown, message?: string): asserts value is DataView {\n\tif (!isDataView(value)) {\n\t\tthrow new TypeError(message ?? typeErrorMessage('DataView', value));\n\t}\n}\n\nexport function assertDate(value: unknown, message?: string): asserts value is Date {\n\tif (!isDate(value)) {\n\t\tthrow new TypeError(message ?? typeErrorMessage('Date', value));\n\t}\n}\n\nexport function assertDirectInstanceOf<T>(instance: unknown, class_: Class<T>, message?: string): asserts instance is T {\n\tif (!isDirectInstanceOf(instance, class_)) {\n\t\tthrow new TypeError(message ?? typeErrorMessage('T', instance));\n\t}\n}\n\nexport function assertEmptyArray(value: unknown, message?: string): asserts value is never[] {\n\tif (!isEmptyArray(value)) {\n\t\tthrow new TypeError(message ?? typeErrorMessage('empty array', value));\n\t}\n}\n\nexport function assertEmptyMap(value: unknown, message?: string): asserts value is Map<never, never> {\n\tif (!isEmptyMap(value)) {\n\t\tthrow new TypeError(message ?? typeErrorMessage('empty map', value));","sourceCodeStart":1526,"sourceCodeEnd":1562,"githubUrl":"https://github.com/sindresorhus/is/blob/7821031c66cdeb7256a0feb2d506535f9e84fcaf/source/index.ts#L1526-L1562","documentation":"Thrown by `assertDate()` when the value fails `isDate` (object type 'Date'). It guarantees Date-instance methods are available; note it does NOT reject invalid dates (`new Date('garbage')` still passes — that's `assert.validDate`).","triggerScenarios":"Calling `assert.date(value)` with an ISO date string, a Unix timestamp number, a Moment/Dayjs/Luxon object, or a date that went through JSON serialization (JSON turns Dates into strings).","commonSituations":"API responses and database JSON columns deliver dates as ISO strings; `JSON.parse` never revives Dates; ORMs configured to return strings; timestamps stored as epoch numbers; date-library wrapper objects passed where native Date is required.","solutions":["Convert at the boundary: `new Date(isoStringOrTimestamp)` before asserting.","For date-library objects, call their native conversion (`m.toDate()`, `dt.toJSDate()`).","If invalid dates must also be rejected, use `assert.validDate` instead.","Add a JSON reviver or DTO mapping layer so dates are revived once, centrally."],"exampleFix":"// before\nassert.date(apiResponse.createdAt);\n// after\nassert.date(new Date(apiResponse.createdAt));","handlingStrategy":"validation","validationCode":"const date = value instanceof Date ? value : new Date(value);\nif (Number.isNaN(date.getTime())) {\n  throw new Error(`Unparseable date input: ${String(value)}`);\n}","typeGuard":"function isDate(value: unknown): value is Date {\n  return value instanceof Date;\n}","tryCatchPattern":"try {\n  assert.date(value);\n} catch (error) {\n  if (error instanceof TypeError) {\n    // ISO string or epoch number slipped through — parse to Date at the deserialization boundary\n  } else throw error;\n}","preventionTips":["JSON has no Date type — revive ISO strings to Date immediately after JSON.parse, before values propagate","Also check for Invalid Date (Number.isNaN(d.getTime())) — instanceof alone passes invalid dates","Library Date objects (Moment, Day.js, Luxon DateTime) are not Date — call .toDate()/.toJSDate() first"],"tags":["type-assertion","date","serialization","json"],"analyzedSha":"7821031c66cdeb7256a0feb2d506535f9e84fcaf","analyzedAt":"2026-07-31T18:34:06.268Z","schemaVersion":2}