Accept number in string type
Hello! I'm parsing each value in a form with
JSON.parse
to convert string values like false
to actual booleans. Unfortunately, this introduces the issue, that if someone inputs 123
into a text field, it gets parsed into a number type by JSON.parse
. Then if the field is type string
. An error is thrown, since number is not assignable to string.
How should a type look like, if it should handle such a situation?...Automatically applying parse.integer
Let's say I have a type I'm using to validate some API, e.g.
```
const personSchema = type({
name:'string',
age:'0<=number<=120'...
Extract type from or
Hello! Is it possible, using the following schema:
```ts
const userType = type({
intent: "'profile'",
name: 'string>0',...
Get type without constraints
Hello!
inferAmbient
retuns types with constraints like moreThanLength<0>
, which when I try to access values to, I get Type 'string' is not assignable to type 'moreThanLength<0>'
.
Is it possible to extract a more basic type?...codecs
with morphs, I am thinking of arktype types as sort of input/output functions
for
const t = type(...)
t.allows(input)
tells if you if input is the right shape
t(input)
takes input and turns it into output (or errors)
...How to handle checkbox in type('parse.formData').to(...)
I want turn the checkbox into boolean, but the checkbox field only produce "on" when checked, and missing when unchecked...
Latest "keys:distilled" equivalent?
Hello, I started using ArkType a back in v1 and it has obviously come on leaps and bounds since then which is great to see.
However, back in v1 you could do something like ```ts
export const loginPayload = type(
{...
Is it possible to extract a "subtype"?
Hi,
I'm looking into Arktype for the first time, so please forgive me if this is a noob question 😅
I wanna extract a "subtype"/"subschema" from a schema. I don't know how describe it better other than a code example:...
Error internationalization (i18n)
Hello! Is it possible to translate the errors into other languages?
In my previous setup I was using this for such funtionality:
https://github.com/aiji42/zod-i18n
...
Tried to initialize an $ark registry in a monorepo
Hello! In a
pnpm
workspace, I have 2 packages depending on arktype
. This means that each package depends on arktype
separately. However, when I import them into a central vite
project, I get the error:
```
Tried to initialize an $ark registry but one already existed. This probably means you are either depending on multiple versions of an arktype package, or importing the same package from both ESM and CJS.
Review package.json versions across your repo to ensure consistency....Adding comment to object key
Hello! What would be the right way to add comments to an object's key, like you do with
/** */
?
I tried this, but it didn't work:
```ts
output: type({...Optional key
Hello! How can I define an array, which is also not required as an optional key? Is this the easiest way? https://discord.com/channels/957797212103016458/957804102685982740/1213198676349026355
```ts
// Goal:
{...
Convert string to number with constraints
Hi, I'm looking at switching from Zod to Arktype mainly based on the serializable nature of types (lots of database driven forms).
I'm stuck on something I think should be simple...
- I'm passing FormData to the server.
- Some of the fields are numeric, but are passed as strings (as FormData does)...
Are there examples of how to create mapped types?
e.g. a
{ [K in <SomeOtherType>]: SomeValueType }
type, where SomeValueType
is either a static type or is computed from K.
I currently have a very basic setup where I have:
```ts
type MappedEnum<T extends string> = { readonly [K in T]: T };...ArkType mutates original input?
I was always under the assumption that ArkType leaves the original input intact. However:
```ts
import { type } from "arktype";
const original = { value: "100" };...
How to accept a generic non-empty const string array for use in `type`?
Note: this may be a TS question, feel free to send me there instead.
I have the following type:
PgEnum<TValues extends [string, ...string[]]> { enumValues: TValues; }
I'm attempting to create a function which accepts this object and returns an arktype instance of the union of the strings in the array, which is const with well-known values....using an const array as a source for a string literal union
Given this:
```ts
const weatherIcons = [
'sun',...