storyblok / storyblok-js-client

Universal JavaScript client for Storyblok's API
MIT License
129 stars 87 forks source link

Type definition error in the addNode method of the RichTextResolver #409

Closed snk7891 closed 1 year ago

snk7891 commented 1 year ago

storyblok.com

When using the RichTextResolver to customize the rendered HTML, the addNode method expects a ISbSchema as the second parameter, but it should accept a function instead.

ISbSchema type definition for reference:

export interface ISbSchema {
    nodes: any;
    marks: any;
}

But when the field is accessed, a function is expected, as you can see here: https://github.com/storyblok/storyblok-js-client/blob/a436f209c1d63aff6198ee10afba1219028249bd/source/richTextResolver.js#L154-L159


Expected Behavior

We use the following code to create automatically some headings; typescript should not complain about the type definition of the second parameter of the addNode method:

const richTextResolver = new RichtextResolver();
richTextResolver.addNode("heading", (node) => {
  const { level, ...otherAttrs } = node.attrs;
  return {
    tag: [
      {
        tag: `h${level}`,
        attrs: otherAttrs,
      },
    ],
  };
});

Current Behavior

Getting the following error:

Argument of type '(node: any) => { tag: { tag: string; attrs: any; }[]; }' is not assignable to parameter of type 'ISbSchema'.
  Type '(node: any) => { tag: { tag: string; attrs: any; }[]; }' is missing the following properties from type 'ISbSchema': nodes, marks

Steps to Reproduce

You can copy the code above to have a type error

thiagosaife commented 1 year ago

Hi @snk7891 Thanks for the heads up. We'll take a look on this one.

thiagosaife commented 1 year ago

@snk7891 Hello, sir. When you have the time, please check our latest version. It should solve this issue. I'll close this one, but feel free to open another one if needed.