Skip to content
This repository has been archived by the owner on Jul 16, 2024. It is now read-only.

Commit

Permalink
int filter: use Number.isSafeInteger instead of Number.isInteger
Browse files Browse the repository at this point in the history
  • Loading branch information
gcanti committed Sep 28, 2023
1 parent 9d95902 commit d8abd97
Show file tree
Hide file tree
Showing 4 changed files with 10 additions and 3 deletions.
5 changes: 5 additions & 0 deletions .changeset/young-terms-wink.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@effect/schema": patch
---

int filter: use Number.isSafeInteger instead of Number.isInteger
2 changes: 1 addition & 1 deletion src/Schema.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1973,7 +1973,7 @@ export const IntTypeId = Symbol.for("@effect/schema/TypeId/Int")
export const int =
<A extends number>(options?: FilterAnnotations<A>) => <I>(self: Schema<I, A>): Schema<I, A> =>
self.pipe(
filter((a): a is A => Number.isInteger(a), {
filter((a): a is A => Number.isSafeInteger(a), {
typeId: IntTypeId,
description: "integer",
jsonSchema: { type: "integer" },
Expand Down
2 changes: 1 addition & 1 deletion test/Schema/fromBrand.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import * as Util from "@effect/schema/test/util"

type Int = number & Brand.Brand<"Int">
const Int = Brand.refined<Int>(
(n) => Number.isInteger(n),
(n) => Number.isSafeInteger(n),
(n) => Brand.error(`Expected ${n} to be an integer`)
)

Expand Down
4 changes: 3 additions & 1 deletion test/number/int.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import * as Pretty from "@effect/schema/Pretty"
import * as S from "@effect/schema/Schema"
import * as Util from "@effect/schema/test/util"

const schema = S.number.pipe(S.int())
const schema = S.Int

describe("number/int", () => {
it("property tests", () => {
Expand All @@ -15,6 +15,8 @@ describe("number/int", () => {
expect(is(0)).toEqual(true)
expect(is(1)).toEqual(true)
expect(is(0.5)).toEqual(false)
expect(is(Number.MAX_SAFE_INTEGER + 1)).toEqual(false)
expect(is(Number.MIN_SAFE_INTEGER - 1)).toEqual(false)
})

it("decoding", async () => {
Expand Down

0 comments on commit d8abd97

Please sign in to comment.