Skip to content

Make "number" reject Infinity, or make it easy to parse only finite numbers #1598

@guillaumebrunerie

Description

@guillaumebrunerie

Request a feature

It should be easy to parse a finite number. In Zod 4, z.number() rejects ±Infinity, but ArkType's "number" seems to accept them.

🤷 Motivation

When parsing a number, it is usually pretty rare for Infinity or -Infinity to be a valid value, and also easy to forget about it. This means that by default, ArkType will often accept invalid data.

💡 Solution

My preferred solution would be to match Zod's behavior: to change "number" so that it rejects Infinity and -Infinity.

Alternatively, you could provide a "number.finite" primitive.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    Status

    To do

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions