Skip to content

Node type and view interface inference from schema #805

Closed Answered by streamich
marolbrich asked this question in Q&A
Discussion options

You must be logged in to vote

What ist the correct type of the node?

  1. The schema is stored in SimpleObjectSchema, you can extract the node type and view interface from it.
  2. The schema also sets the default value, so you don't need to do .api.root(), the schema does it for you.

Basically, what you want to write is:

const SimpleObjectSchema = s.obj({
  text: s.con<string>('foo'),
});

const model = Model.create(SimpleObjectSchema);

type SimpleObjectNodeType = SchemaToJsonNode<typeof SimpleObjectSchema>;
type SimpleObjectI = JsonNodeView<SimpleObjectNodeType>;

console.log(model + '');

The SchemaToJsonNode and JsonNodeView types you can import from the library.

Replies: 5 comments

Comment options

You must be logged in to vote
0 replies
Comment options

You must be logged in to vote
0 replies
Answer selected by streamich
Comment options

You must be logged in to vote
0 replies
Comment options

You must be logged in to vote
0 replies
Comment options

You must be logged in to vote
0 replies
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants
Converted from issue

This discussion was converted from issue #801 on January 15, 2025 09:20.