You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I am probably missing an easy to spot error but I wanted to ask here since I could not figure out. I am experimenting on a WYSIWYG editor. I was working on paragraph nodes and I could not get Typescript to interpret types. I am attaching code below.
import * as z from "zod";
import { baseSchema } from "./base";
// Schema for TextNode
export const textNodeSchema = baseSchema.extend({
type: z.literal("text"),
content: z.string(),
});
export type TextNode = z.infer<typeof textNodeSchema>;
export const boldNodeSchema = baseSchema.extend({
type: z.literal("bold"),
children: z.array(z.lazy(() => inlineNodeSchema)).default([]),
});
export type BoldNode = z.infer<typeof boldNodeSchema>;
// Schema for ItalicNode (using z.lazy for children)
export const italicNodeSchema = baseSchema.extend({
type: z.literal("italic"),
children: z.array(z.lazy(() => inlineNodeSchema)).default([]),
});
export type ItalicNode = z.infer<typeof italicNodeSchema>;
// Schema for LinkNode (using z.lazy for children)
export const linkNodeSchema = baseSchema.extend({
type: z.literal("link"),
href: z.string().url("Invalid URL format"),
children: z.array(z.lazy(() => inlineNodeSchema)).default([]),
});
export type LinkNode = z.infer<typeof linkNodeSchema>;
export type InlineNode = TextNode | BoldNode | ItalicNode | LinkNode;
// Define the lazy union schema for InlineNode
// This schema implements the InlineNode type alias defined earlier
export const inlineNodeSchema: z.ZodType<InlineNode> = z.lazy(() =>
z.union([textNodeSchema, boldNodeSchema, italicNodeSchema, linkNodeSchema])
);
I get 'inlineNodeSchema' is referenced directly or indirectly in its own type annotation. and Type alias 'InlineNode' circularly references itself. when I add type hint to inlineNodeSchema. If I remove evevrything becomes any. It works but I would like to carry over the types.
reacted with thumbs up emoji reacted with thumbs down emoji reacted with laugh emoji reacted with hooray emoji reacted with confused emoji reacted with heart emoji reacted with rocket emoji reacted with eyes emoji
-
Hello,
I am probably missing an easy to spot error but I wanted to ask here since I could not figure out. I am experimenting on a WYSIWYG editor. I was working on paragraph nodes and I could not get Typescript to interpret types. I am attaching code below.
I get 'inlineNodeSchema' is referenced directly or indirectly in its own type annotation. and Type alias 'InlineNode' circularly references itself. when I add type hint to inlineNodeSchema. If I remove evevrything becomes any. It works but I would like to carry over the types.
Thank you.
Beta Was this translation helpful? Give feedback.
All reactions