itsyoboieltr
itsyoboieltr
Explore posts from servers
Aarktype
Created by itsyoboieltr on 9/8/2024 in #questions
Creating default object from type definition
thanks for taking your time to answer and provide detailed answers!
23 replies
Aarktype
Created by itsyoboieltr on 9/8/2024 in #questions
Creating default object from type definition
and we'll see
23 replies
Aarktype
Created by itsyoboieltr on 9/8/2024 in #questions
Creating default object from type definition
but I guess this would also be useful for others, so I'll make an issue about it
23 replies
Aarktype
Created by itsyoboieltr on 9/8/2024 in #questions
Creating default object from type definition
true
23 replies
Aarktype
Created by itsyoboieltr on 9/8/2024 in #questions
Creating default object from type definition
Maybe a better description instead of default would be something like: "simplest representation"
23 replies
Aarktype
Created by itsyoboieltr on 9/8/2024 in #questions
Creating default object from type definition
yeah, exactly. If something is optional, it shouldn't exist, if something is nullable, it should be null, etc.
23 replies
Aarktype
Created by itsyoboieltr on 9/8/2024 in #questions
Creating default object from type definition
I would expect arrays to be empty yeah. About unions I am unsure though...
23 replies
Aarktype
Created by itsyoboieltr on 9/8/2024 in #questions
Creating default object from type definition
so a good rule of thumb would be to respect the primitives, but ignore the spicy constraints (in my opinion) for default generation
23 replies
Aarktype
Created by itsyoboieltr on 9/8/2024 in #questions
Creating default object from type definition
I think it would be a great first step to support the primitive, simple use-cases, which is what most people would need this feature for. I think for the use-case I am talking about, it would be relatively simple to make something work. I would propose that we ignore regexes, length, and all the other stuff, as the generated default value is not supposed to be correct (does not need to pass type validation), as I expect the user in the frontend to update this value to make it correct at the time of submission. This is the original code, basically the reason why this feature should be implemented:
import { type } from 'arktype';

export const user = type({ name: 'string' });

export const getDefaultUser = () => ({ name: '' });
import { type } from 'arktype';

export const user = type({ name: 'string' });

export const getDefaultUser = () => ({ name: '' });
Let's say I update the user type's name property to match a regex pattern. I would still want the default user's name to have a value of an empty string, as the user will need to enter his name. The generated default name does not need to match the regex pattern.
import { type } from 'arktype';

export const user = type({ name: /^([A-Za-z]+)\s([A-Za-z]+)$/ });

export const getDefaultUser = () => ({ name: '' });
import { type } from 'arktype';

export const user = type({ name: /^([A-Za-z]+)\s([A-Za-z]+)$/ });

export const getDefaultUser = () => ({ name: '' });
Similar for length, and other properties:
import { type } from 'arktype';

export const user = type({ name: 'string > 10' });

export const getDefaultUser = () => ({ name: '' });
import { type } from 'arktype';

export const user = type({ name: 'string > 10' });

export const getDefaultUser = () => ({ name: '' });
I wouldn't expect a random 10 character string to be generated here. (By the way, in TypeBox, this would generate: 'aaaaaaaaaa') So maybe a practical solution is easier than you first thought? Of course, if your goal is to create a default value that is 100% according to the type and passes validation, then it can get complex pretty quick. But most of the time, default values are not expected to conform to the type, as they are supposed to be updated later (in the use-case of generating initial state for a form).
23 replies
TtRPC
Created by itsyoboieltr on 7/9/2024 in #❓-help
Cron job with tRPC
for reference: Elysia is using Croner to implement cron jobs https://github.com/hexagon/croner, I wonder how would this be used in the context of tRPC with a next.js app
2 replies
SSolidJS
Created by gabriel on 3/7/2024 in #support
How can I only set the ref for an element once it's been inserted into the DOM?
the only solution that worked for me is to migrate my tooltip, and popover components to corvu https://corvu.dev/docs/, which also uses floating-ui, but does not have this issue 😄
47 replies
SSolidJS
Created by gabriel on 3/7/2024 in #support
How can I only set the ref for an element once it's been inserted into the DOM?
btw I did all the things that were mentioned here and it is still not working, so I had to scrap solid-floating-ui from my project 😦
47 replies
DTDrizzle Team
Created by itsyoboieltr on 10/19/2023 in #help
Drizzle typebox enum array not working
RIP drizzle-typebox
10 replies
DTDrizzle Team
Created by itsyoboieltr on 10/19/2023 in #help
Drizzle typebox enum array not working
any news on this? 😛
10 replies
SSolidJS
Created by itsyoboieltr on 11/30/2023 in #support
Is there a way to use the <For> component with an array of inputs?
some feedback to the solid team: it could be that I missed this, but this probably should be more emphasized somehow when using stores. I believe all people coming from react will do it like I tried initially lol
4 replies
SSolidJS
Created by itsyoboieltr on 11/30/2023 in #support
Is there a way to use the <For> component with an array of inputs?
TLDR: do not make a deep copy of the whole store and modify the copied array like you would in react, just use the built in helper methods so you do not recreate the whole array on every key press
4 replies
SSolidJS
Created by itsyoboieltr on 11/30/2023 in #support
Is there a way to use the <For> component with an array of inputs?
4 replies