[FIXED] [Bug (react-datocms)] StructuredText's incorrect typings on blocks/links

Hi!

I found the ability to put GraphQL responses directly into <StructuredText /> component to be really useful and I love to use it.

However, while I was working on adding a new block to my post I noticed the weird type error happening. I added a new entry to blocks but the type error suggested that I have a mistake on links.
After some research I found out this code piece:

export declare type StructuredText<R extends Record = Record> = {
    /** A DatoCMS compatible document */
    value: Document;
    /** Blocks associated with the Structured Text */
    blocks?: R[];
    /** Links associated with the Structured Text */
    links?: R[];
};

This model of structured text is incorrect because not all block records are necessarily valid link records. For example, if I allowed articles to be linked but not say, tweets, it would cause problems because the properties of those two don’t match up yet they have to be the same type.

I’ve been able to fix this for myself using patch-package, but it would be great to see this being fixed on upstream too.

1 Like

Hello @basix

We merged your pull request! https://github.com/datocms/structured-text/pull/21

Thank you so much for the contribution!

Aw man this is the beauty of the open-source. I’m glad that I can contribute back to my beloved tools <3