-
-
Notifications
You must be signed in to change notification settings - Fork 255
feat: create coercion actions for primitives (and date) #1212
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Conversation
The latest updates on your projects. Learn more about Vercel for Git ↗︎
|
Thank you so much!
Yes, we should do that whenever it is necessary to cover all edge cases
I would only convert it. Do you know what Zod is doing here? |
with Zod the coercion isn't separate from the schema (it just happens as the first step of the schema if configured), so |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Pull Request Overview
This PR adds a set of conversion actions for primitives—including string, number, date, boolean, and bigint—along with comprehensive tests and type validations.
- Introduces conversion functions for each type with try-catch logic for error handling
- Adds tests to validate both successful coercions and proper issue reporting on invalid inputs
- Updates re-export files to include the newly added actions
Reviewed Changes
Copilot reviewed 50 out of 50 changed files in this pull request and generated 1 comment.
Show a summary per file
File | Description |
---|---|
library/src/actions/toString/* | Adds toString conversion action and tests |
library/src/actions/toNumber/* | Introduces toNumber conversion with error handling |
library/src/actions/toDate/* | Implements toDate conversion with try-catch (see note) |
library/src/actions/toBoolean/* | Adds toBoolean conversion action and tests |
library/src/actions/toBigint/* | Introduces toBigint conversion with error handling |
library/src/actions/index.ts | Updates exports to include the new conversion actions |
dataset.value = new Date(dataset.value); | ||
} catch { | ||
_addIssue(this, 'date', dataset, config); | ||
// @ts-expect-error | ||
dataset.typed = false; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
new Date() does not throw an exception for invalid date strings; consider validating the resulting Date (e.g., checking if isNaN(dataset.value.getTime())) and registering an issue if it's invalid.
dataset.value = new Date(dataset.value); | |
} catch { | |
_addIssue(this, 'date', dataset, config); | |
// @ts-expect-error | |
dataset.typed = false; | |
const parsedDate = new Date(dataset.value); | |
if (isNaN(parsedDate.getTime())) { | |
_addIssue(this, 'date', dataset, config); | |
// @ts-expect-error | |
dataset.typed = false; | |
} else { | |
dataset.value = parsedDate; | |
} |
Copilot uses AI. Check for mistakes.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think right now we want devs to explicitly handle this case with v.pipe(v.unknown(), v.toDate(), v.date())
.
Decisions left:
Number(Symbol())