morphing to typescript type
I tried to do a narrow + pipe.try on
type("string")
to try to parse out a Temporal.ZonedDateTime
type to sort of replicate what type("string.date.iso.parse")
does, and it mostly works. But I've noticed if I infer the TS type I can't actually assign a Temporal.ZoneDateTime
to the field, as tsc complains that the valueOf
signatures are different. Is this supposed to work, or should I be venturing down the path of scopes and rootSchema
instead?
```typescript
const zonedDateTimeISO = type("string")
.narrow((date, ctx) => {...Generic middleware validator
Hello, I'm trying to write a middleware in my app that handles validating the incoming request body. It currently looks like this
```ts
export function validateBody<T extends Type>(
validator: T
): MiddlewareObj<ValidatedBody<T["infer"]>> {...
Compiling scope to interfaces
I have a huge scope and I want to extract 10+ interfaces from it, preferably in a way that would compile plainly to d.ts
And then remake the scope with using those interfaces
```ts...
Union of generics
I've tried to write the following :
```ts
export const arkQueryCriteriaValue = type('<Value>', [
{ eq: 'Value' },...
Merging types instead of using an intersection when using generics
I have a generic type like this one :
...
generic('T', 'M')([ 'T', '&', { metadata: { id: 'M' }} ])
generic('T', 'M')([ 'T', '&', { metadata: { id: 'M' }} ])
Generic & intersection
I'm looking to have a helper
arkWithMetadata
, which basically takes a base type and add { metadata: { id: <id> }}
I wanted to write this :
```ts
export const arkWithMetadata = type(
'<doc extends Record<string, unknown>, id extends string>',...Is there a way to morph an optional value back to a required one?
the example bellow always returns a number, but is typed as {PORT?: number | undefined}
...
const schema = type({
PORT: ['string?', '=>', (v?: string) => parseInt(v ?? '3000')]
})
const schema = type({
PORT: ['string?', '=>', (v?: string) => parseInt(v ?? '3000')]
})
Generic modules, Enums and AnyOf
There are at least 3 threads asking for
OneOf
I suggest making a Enum generic (called OneOf
maybe) that works as following:
- it accepts an object definition O
- it has a root type which allows any of the property values O[keyof O]
- it is a module with all property types as its values, Module<{ [K in keyof O]: Type<O[K]> }>
...Multiple @ark registries detected
I'm receiving this error in a Nextjs app:
...
Multiple @ark registries detected. This can lead to unexpected behavior.
Multiple @ark registries detected. This can lead to unexpected behavior.
File type
I noticed you can do types like File, I was wondering if it's possible to do things like validate file size?
Type definitions must be strings or objects (was undefined)
Hello!
When importing a module that is using Arktype, I get the error
Type definitions must be strings or objects (was undefined)
. I am not sure what it means. What should I be looking for to solve it?...Function which receives a arktype's 'type'
I'm trying to do something like this:
```ts
async rateLimitedCallApi<T>(url: string, schema: Type<T>): Promise<T> {
await this.rate_limiter.acquire();
...
Conform to an existing type
Hello! Is there a way to force a def to conform to an existing typescript type?
```ts
export const chatDef = type({
id: 'number',...
Using `atLeastLength` on morphed array
How do I do
```ts
it("can use atLeastLength on piped array", () => {
const SortedArray = type("string[]").pipe(s => s.sort()).to('string[]')
const NonEmptySortedArray = SortedArray.atLeastLength(1)...
Partial Application of the validator
Is there any way to partially apply the validator
for eg:
```ts
const test = type({
name: "string",...
Customizing Error Messages
I've searched Github & Discord a bit and seen a few mentions of "full error customization", and am finding that I need it, but can't find any examples of it.
I have a type:
```ts
const form = type({...
v2 docs
I see the v2 docs mentioned frequently here and in GitHub, but I can’t find a link to them.
Are they deployed?
Even if they’re a WIP, they’d be extremely valuable to have I think...
Pipe chains don't work in rc13
I'm trying to make a logging wrapper to help me debug my Types
but pipes don't seem to chain
```ts
function logWrapper<T extends type.Any>(T: T): T {...
Node of kind optional is not valid as a required definition
Hello! Whenever I use a type with an optional key with a default value like this:
```ts
const def = type({
'agree?': 'boolean = true',...