Skip to content

Custom signals support #3

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

Open
MarceloPrado opened this issue Jul 1, 2023 · 1 comment
Open

Custom signals support #3

MarceloPrado opened this issue Jul 1, 2023 · 1 comment

Comments

@MarceloPrado
Copy link
Contributor

After reading the Custom Type docs, I tried creating a custom date signal. I'm not sure the right way of injecting custom assert functions. For example, the number operator adds its own set of functions. I would like to do the same for my types.

For example:

const dateSignal = signal.type<Date>(z.date().parse)

I'm trying to understand how to enhance its types to support operations besides the basic ones:

CleanShot 2023-07-01 at 18 18 50@2x

Given dates are a non-trivial type, it would be awesome if I could add operations like isSameDay, isAfter, isBefore, etc.

@MarceloPrado
Copy link
Contributor Author

MarceloPrado commented Jul 1, 2023

Turns out I can build a similar feature by using a regular number signal:

  dayOfMonth: signal.number.value<Date>((value) => getDate(value)),
  dayOfWeek: signal.number.value<Date>((value) => getISODay(value)),

Then, I can use the number assertions to achieve my goal.

Nonetheless, I'm really curious if my idea above is even possible. I've looked at the internals, but I need some time to get familiar with the TS gymnastics that happens in the signal/factory.ts 😂

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

No branches or pull requests

1 participant