TypeScript code generation and StructuredText value types

I was just running into this issue yesterday. I did try to use the
JsonField: "StructuredText<Record, Record>" in the codegen.yml, which did work for structured text fields. For future travellers I also had to add

      - add:
          content: "import { type Record, type StructuredText } from  'datocms-structured-text-utils';"

to the codegen.yml, borrowed from this solution (changing import names as needed to not have clashes).

However, we also have other JsonField type fields in our models, mostly from plugins which use the generic json field to provide additional data (e.g. Word counter - Plugins — DatoCMS) - and having these typed as Structured Text didn’t work for us. In the end I’ve gone back to using unknown for JsonField, and then casting as StructuredText<Record, Record> after getting the response back.

Potentially Structured Text fields could be typed as a more specific version of JsonField in the api so we can have both?

1 Like