diff --git a/.changeset/red-flies-push.md b/.changeset/red-flies-push.md new file mode 100644 index 000000000..0f072b270 --- /dev/null +++ b/.changeset/red-flies-push.md @@ -0,0 +1,5 @@ +--- +"@effect/schema": patch +--- + +Arbitrary: remove NaN while generating numeric template literals diff --git a/src/Arbitrary.ts b/src/Arbitrary.ts index 6e307a28c..55a89f410 100644 --- a/src/Arbitrary.ts +++ b/src/Arbitrary.ts @@ -118,12 +118,14 @@ export const go = (ast: AST.AST, constraints?: Constraints): Arbitrary => { return (fc) => fc.oneof(fc.object(), fc.array(fc.anything())) case "TemplateLiteral": { return (fc) => { + const string = fc.string({ maxLength: 5 }) + const number = fc.float({ noDefaultInfinity: true }).filter((n) => !Number.isNaN(n)) const components: Array> = [fc.constant(ast.head)] for (const span of ast.spans) { if (AST.isStringKeyword(span.type)) { - components.push(fc.string({ maxLength: 5 })) + components.push(string) } else { - components.push(fc.float({ noDefaultInfinity: true })) + components.push(number) } components.push(fc.constant(span.literal)) }