Skip to content

t.Int: use Number.isSafeInteger instead of Number.isIntegerΒ #702

@lukasz-jagielski-bolt

Description

@lukasz-jagielski-bolt

πŸš€ Feature request

Current Behavior

t.Int uses Number.isInteger which is unsafe to use outside of range <Number.MIN_SAFE_INTEGER, Number.MAX_SAFE_INTEGER> (non-integer inputs will return false positive). https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Number/isInteger

Desired Behavior

To be safe t.Int could fail validation of Numbers outside of range <Number.MIN_SAFE_INTEGER, Number.MAX_SAFE_INTEGER>

Suggested Solution

Use Number.isSafeInteger instead of Number.isInteger

Who does this impact? Who is this for?

Everyone using t.Int

Describe alternatives you've considered

Provide a secondary type t.SafeInt?

Additional context

Thanks for a great library, this is something that perhaps could make using it safer :)

Your environment

Software Version(s)
io-ts 2.2.16
fp-ts 2.10.5
TypeScript 4.7.4

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions