TypeScript first - is possible or not? Can't remember :)

Hi folks! I'm not an ArkType regular as I would wish to be, so I may ask the same questions sometimes. Sorry for this. I wonder if it's possible to define TypeScript-first schema, and to pass the type as generic? At first glance it works natively:
type Foo = {
bar: string;
baz: string;
};

// Ark

const foo$ = type<Foo>({
bar: 'string',
baz: 'string'
})
type Foo = {
bar: string;
baz: string;
};

// Ark

const foo$ = type<Foo>({
bar: 'string',
baz: 'string'
})
But it gives never-s in return: So is there a way?
No description
3 Replies
ssalbdivad
ssalbdivad3w ago
Yeah there is, but it is still not a finalized part of the API, so do keep in mind it might still change slightly:
import { declare, type } from "arktype"

type Expected = { a: string; b?: number }
const t = declare<Expected>().type({
a: "string",
"b?": "number"
})
import { declare, type } from "arktype"

type Expected = { a: string; b?: number }
const t = declare<Expected>().type({
a: "string",
"b?": "number"
})
OnkelTem
OnkelTemOP3w ago
Wow, I see David! Thanks!

Did you find this page helpful?