itsyoboieltr
itsyoboieltr
Explore posts from servers
Aarktype
Created by itsyoboieltr on 9/8/2024 in #questions
Creating default object from type definition
Hi! I would like to migrate my project from TypeBox to ArkType, as I love the work you're doing on it, and the development experience seems much better. There is one feature that I love in TypeBox, but couldn't find in ArkType: creating a default object from a type definition. Is this something that exists or was ever raised/considered? I would find this feature very useful to create the initial state of a form, without any code duplication. Example syntax:
import { type } from 'arktype';

export const userType = type({
name: 'string',
device: {
platform: "'android'|'ios'",
'version?': 'number',
},
});

const user = userType.create();
console.log(user)
// {name: '', device: {platform: 'android'}}
import { type } from 'arktype';

export const userType = type({
name: 'string',
device: {
platform: "'android'|'ios'",
'version?': 'number',
},
});

const user = userType.create();
console.log(user)
// {name: '', device: {platform: 'android'}}
23 replies