prismicio / prismic-ts-codegen

A Prismic model-to-TypeScript-type generator.
Apache License 2.0
18 stars 6 forks source link

Incorrect `RichTextField` types #35

Open nandorojo opened 2 years ago

nandorojo commented 2 years ago

Is your feature request related to a problem? Please describe.

Currently, the codegen outputs something like this for RichTextField:

declare type RichTextField<State extends FieldState = FieldState> = State extends "empty" ? [] : [RTNode, ...RTNode[]];

Using State extends "empty" ? [] means that the array is essentially never[] | [RTNode, ...RTNode[]]. This means that looping over items basically never works, because they can also be typed as never.

Screen Shot 2022-09-30 at 4 40 31 PM

Describe the solution you'd like

Rewrite the type like this:

declare type RichTextField<State extends FieldState = FieldState> = RTNode[];

An empty array doesn't require getting typed, right?

Describe alternatives you've considered

Overriding the types manually.

Additional context

nandorojo commented 2 years ago

Just realized this type comes from @prismicio/types.