Hi,

new to arktype, i have two questions: 1. i can't add a default for array ? like : foo:"string[]=['bar']" 2. given a type with all it's default can i create a concrete object from this type with all the default like: const foo=type({bar:"number.integer=42"}) and get back const defObj={bar: 42}
2 Replies
TizzySaurus
TizzySaurus2d ago
You can try foo: type("string[]").default(["bar"]) And for the second, wouldn't just calling the type do that? I.e. foo()/foo({})
papy0977
papy0977OP2d ago
here the snippet i have now it seems that default is expecting for a a function as argument import {type} from "arktype" const base = type( { env:"string='base'", database: { connectionTimeoutMillis: "number.integer=3000", app_db_client: "('pg-node'|'prisma'|'typeorm'|'knex'|'drizzle')='knex'", migrate: type("string[]").default(() => ["no migration"]), } } ) type Base = typeof base.infer const def = base({}) console.log(def.env) and i have def.env is undefined error

Did you find this page helpful?