freeyourmind
Aarktype
•Created by freeyourmind on 2/22/2025 in #questions
How to create a type from json or jsonschema?
It works! Thanks!
6 replies
Aarktype
•Created by freeyourmind on 2/22/2025 in #questions
How to create a type from json or jsonschema?
import { type } from "arktype";
import { schemaScope, rootSchema } from "@arktype/schema";
const bounded = type({
nonEmpty: "string > 0",
atLeastLength3: "string.alphanumeric >= 3",
lessThanLength10: "string < 10",
atMostLength5: "string <= 5",
});
const bounded2 = rootSchema(bounded.json as any);
const types = schemaScope({
bounded: bounded.json as any,
}).export();
const bounded3 = types.bounded;
console.log(bounded2.extends(bounded));
// true
console.log(bounded.extends(bounded2));
// true
console.log(bounded3.extends(bounded));
// true
console.log(bounded.extends(bounded3));
// true
6 replies