Skip to content

Date coercion isn't supported by TypeScript types #682

Closed
@tmcw

Description

@tmcw

Prerequisites

  • I have written a descriptive issue title
  • I have searched existing issues to ensure the bug has not already been reported

Fastify version

4.26.0

Plugin version

No response

Node.js version

20.x

Operating system

macOS

Operating system version (i.e. 20.04, 11.3, 10)

14.3

Description

The readme has the following code example:

const stringify = fastJson({
  title: 'Example Schema with string date-time field',
  type: 'string',
  format: 'date-time'
})

const date = new Date()
console.log(stringify(date)) // '"YYYY-MM-DDTHH:mm:ss.sssZ"'

This is great and desired behavior. But it doesn't typecheck. Here's a TypeScript playground link for the message

Which is:

Argument of type 'Date' is not assignable to parameter of type 'string'.

Steps to Reproduce

Add a string type with format: date-time as the spec for fast-json-stringify

Expected Behavior

No response

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions