Typescript to schema #836
Answered
by
streamich
KieranFleckney
asked this question in
Q&A
-
Hello, I was wondering if it was possible to use existing typescript types as the schema instead of creating new ones for each type? Or a way to create a schema from a typescript type? I see #103 which can convert json-type to typescript but not the other way round. I am missing a doc on this? or is there technical limitation? E.G import { Model } from "json-joy/esm/json-crdt";
import { s } from "json-joy/esm/json-crdt-patch";
type Person = {
name: string;
age: number;
};
const schema = s.obj<Person>({
name: "test",
age: 1,
});
const model = Model.create(schema); Thanks :) |
Beta Was this translation helpful? Give feedback.
Answered by
streamich
Jun 27, 2025
Replies: 1 comment
-
You can use const schema = s.obj({
name: "test",
age: 1,
});
type Person = JsonNodeView<SchemaToJsonNode<typeof schema>>; |
Beta Was this translation helpful? Give feedback.
0 replies
Answer selected by
streamich
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
You can use
JsonNodeView
andSchemaToJsonNode
types to convert your schema to a TypeScript type: