Conversation
| format: 'integer', | ||
| default: 0 | ||
| }), | ||
| t.Number(property) |
There was a problem hiding this comment.
probably a typo? should be Integer and not Number
There was a problem hiding this comment.
adding t.Integer causes infinite recursion:
✗ Params Validator > parse malformed integer [3.00ms]
370 | [
371 | t.String({
372 | format: 'integer',
373 | default: property?.default ?? 0
374 | }),
375 | t.Integer(property)
^
RangeError: Maximum call stack size exceeded.There was a problem hiding this comment.
yeah using t.Integer will lead to infinite recursion, but you could do Type.Integer.
There was a problem hiding this comment.
oops, i've just seen it, noted.
src/type-system.ts
Outdated
| ) | ||
| .Decode((value) => { | ||
| const number = +value | ||
| if (isNaN(number)) return value |
There was a problem hiding this comment.
nan is not a valid integer usually
| [ | ||
| t.String({ | ||
| format: 'integer', | ||
| default: 0 |
There was a problem hiding this comment.
i know Numeric does this too but shouldn't this be property.default?
There was a problem hiding this comment.
this seems to break other tests which I feel are out of scope for this PR:
✓ Replace Schema Type > replace object properties in Union
96 | {
97 | from: t.Number(),
98 | to: () => t.Numeric()
99 | }
100 | )
101 | ).toMatchObject(
^
error: expect(received).toMatchObject(expected)
{
[Symbol(TypeBox.Kind)]: "Object",
properties: {
id: {
[Symbol(TypeBox.Kind)]: "Union",
[Symbol(TypeBox.Transform)]: {
Decode: [Function],
Encode: [Function],
},
anyOf: [
{
[Symbol(TypeBox.Kind)]: "String",
+ default: 0,
- default: 1,
format: "numeric",
+ title: "hello",
type: "string",
},
{
[Symbol(TypeBox.Kind)]: "Number",
default: 1,
title: "hello",
type: "number",
}
],
default: 1,
title: "hello",
},
name: {
[Symbol(TypeBox.Kind)]: "String",
type: "string",
},
},
required: [
"id",
"name"
],
type: "object",
}
- Expected - 1
+ Received + 2
src/type-system.ts
Outdated
| }) | ||
| .Encode((value) => value) as any as TNumber | ||
| }, | ||
| Integer: (property?: NumberOptions): TInteger => { |
There was a problem hiding this comment.
IntegerOptions doesn't exist?
src/type-system.ts
Outdated
| if (!FormatRegistry.Has('integer')) | ||
| FormatRegistry.Set( | ||
| 'integer', | ||
| (value) => !!value && !isNaN(+value) && Number.isInteger(+value) |
There was a problem hiding this comment.
Number.isInteger already check for NaN values.
Co-authored-by: Zoe Roux <zoe.roux@zoriya.dev>
fixes #949