TizzySaurus
TizzySaurus
Aarktype
Created by freeyourmind on 2/22/2025 in #questions
How to create a type from json or jsonschema?
I believe type.json is what gives the internal schema I'm referring to. Not sure if that's the same as type.toJSON() (can't remember what that does, and I don't see it in the docs)
5 replies
Aarktype
Created by freeyourmind on 2/22/2025 in #questions
How to create a type from json or jsonschema?
JSON Schema to ArkType is something I've actually got a PR up for that'll hopefully be merged soon™️. https://github.com/arktypeio/arktype/pull/1159 There is rootSchema from @ark/schema, which converts the ArkType internal schema (from type.toJSON() ig?) (the thing that looks like {domain: "number"} for type("number")) into an actual ArkType type. It obviously won't work for non-json-serialisable types like things with morphs etc. though
5 replies
Aarktype
Created by jhechtf on 2/21/2025 in #questions
TypeScript complaining about passing a type from a custom scope to custom helper function
You may not even need the explicit return type
8 replies
Aarktype
Created by jhechtf on 2/21/2025 in #questions
TypeScript complaining about passing a type from a custom scope to custom helper function
I.e. something like this should work:
export const validateObject = <T extends type.Any>(obj: unknown, validator: T): T["infer"] => validator.assert(obj)
export const validateObject = <T extends type.Any>(obj: unknown, validator: T): T["infer"] => validator.assert(obj)
8 replies
Aarktype
Created by jhechtf on 2/21/2025 in #questions
TypeScript complaining about passing a type from a custom scope to custom helper function
And the canonical function body would be just return validator.assert(obj), which will automatically throw an error when the validation fails (so you don't need the instanceof type.errors)
8 replies
Aarktype
Created by jhechtf on 2/21/2025 in #questions
TypeScript complaining about passing a type from a custom scope to custom helper function
And the canonical return type would be T["infer"] rather than using a conditional type (the conditional type is unnecessary because of the extends in the generic declaration)
8 replies
Aarktype
Created by jhechtf on 2/21/2025 in #questions
TypeScript complaining about passing a type from a custom scope to custom helper function
Iirc you just need to change Type<any> to Type<any, any>. I believe there's also type.Any as a shorthand.
8 replies
Aarktype
Created by outsideurimagination on 2/16/2025 in #questions
flatMorph in a type
What type were you expecting?
6 replies
Aarktype
Created by outsideurimagination on 2/16/2025 in #questions
flatMorph in a type
I also seem to remember template literals not being supported, although not certain of that
6 replies
Aarktype
Created by outsideurimagination on 2/16/2025 in #questions
flatMorph in a type
Have you tried that?
6 replies
Aarktype
Created by outsideurimagination on 2/16/2025 in #questions
flatMorph in a type
Surely the 'string' has to be const too?
6 replies
Aarktype
Created by GreggOD on 2/12/2025 in #questions
Is there a better way to do '.or' ?
There's tuple syntax, which you might prefer:
const preType = type(...);

const t = type([
preType.and({foo: "'event'"}),
"|",
preType.and({foo: "'vendor'"})
]);
const preType = type(...);

const t = type([
preType.and({foo: "'event'"}),
"|",
preType.and({foo: "'vendor'"})
]);
3 replies
Aarktype
Created by Father Christmas on 2/9/2025 in #questions
What is the ArkType equivalent of Zod's safeParse?
You're just checking if (result instanceof type.errors) instead of if (result.success === false)
18 replies
Aarktype
Created by Father Christmas on 2/9/2025 in #questions
What is the ArkType equivalent of Zod's safeParse?
I don't really see the difference... either way you need an if statement to handle it
18 replies
Aarktype
Created by Father Christmas on 2/9/2025 in #questions
What is the ArkType equivalent of Zod's safeParse?
Because "non throwing" is the default behavior, as outlined here: https://arktype.io/docs/intro/your-first-type#validate
18 replies
Aarktype
Created by Father Christmas on 2/9/2025 in #questions
What is the ArkType equivalent of Zod's safeParse?
What are you after that what I sent doesn't do?
18 replies