Skip to content

A float value is always output for z.number().int(), when the property name is set to next, if it is not fatalistic #249

@aiya000

Description

@aiya000

Reproduction

  1. Run $ npm run run at the terminal of below URL:

Detail

SSIA

Code

import { z } from 'zod'
import { generateMock } from '@anatine/zod-mock'

const schema = z.object({
  next: z.number().int(), // the property 'next' will never be an int (be a float)
  otherProps: z.number().int(), // other properties will be an int correctly
  nested: z.object({
    next: z.number().int(), // same as the above 'next' property
  }),
})
const mock = generateMock(schema)
console.log(mock)

// $ npm run run
// {
//   next: 0.4105653762107577,
//   otherProps: 6368046635644351,
//   nested: {
//     next: 0.7659188017942997,
//   },
// }
//
// $ npm run run
// {
//   next: 0.5737404892986545,
//   otherProps: 7990334772728833,
//   nested: {
//     next: 0.7744221806853101,
//   },
// }
//
// $ npm run run
// {
//   next: 0.19289757416562037,
//   otherProps: 2205544041244906,
//   nested: {
//     next: 0.6761322483941822,
//   },
// }
//
// $ npm run run
// {
//   next: 0.04695642220068308,
//   otherProps: 7606587734425456,
//   nested: {
//     next: 0.01717930105667087,
//   },
// }
//
// $ npm run run
// {
//   next: 0.2164101780277775,
//   otherProps: 6981326417384630,
//   nested: {
//     next: 0.19683404773381707,
//   },
// }

Correct state

generateMock(z.object({ next: z.number().int() })).next must be an int value.

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