Skip to content

fix: don't coerce strings#87

Merged
mnahkies merged 2 commits into
mainfrom
mn/fix/dont-coerce-string
Oct 31, 2023
Merged

fix: don't coerce strings#87
mnahkies merged 2 commits into
mainfrom
mn/fix/dont-coerce-string

Conversation

@mnahkies

Copy link
Copy Markdown
Owner

coercing strings causes issues with objects like {foo: undefined} as it coerces undefined to "undefined" rather than leaving it as undefined / throwing an error if the property is not optional.

coercing numbers doesn't seem to suffer the same issue, and is needed for parameters from route params / query strings since these always start as a string.

the schema builder should probably become aware of when to expect to receive a parsed JSON value rather than a string and adjust it's use of coerce accordingly, but this will improve things in the meantime.

coercing strings causes issues with objects like `{foo: undefined}`
as it coerces `undefined` to `"undefined"` rather than leaving it as
`undefined` / throwing an error if the property is not optional.

coercing numbers doesn't seem to suffer the same issue, and is needed
for parameters from route params / query strings since these always
start as a string.

the schema builder should probably become aware of when to
expect to receive a parsed JSON value rather than a string and adjust
it's use of coerce accordingly, but this will improve things in the
meantime.
@mnahkies mnahkies marked this pull request as ready for review October 31, 2023 14:35
@mnahkies mnahkies enabled auto-merge (rebase) October 31, 2023 14:36
@mnahkies mnahkies merged commit 56acd67 into main Oct 31, 2023
@mnahkies mnahkies deleted the mn/fix/dont-coerce-string branch October 31, 2023 14:39
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant