storyblok-cli icon indicating copy to clipboard operation
storyblok-cli copied to clipboard

Type generation of single-choice element wrong

Open TwoBee opened this issue 5 months ago • 1 comments

Current behavior: In my Storyblok instance I declared a Button-blok which has a color option. This option is a single-choice element which gets its data from a datasource called "Colors". This datasource containst key-value-pairs like this:

[
  Green: primary,
  Gold: secondary,
  White: white,
  Accent: accent,
  Transparent: transparent
]

This now generates in a Button-blok to this:

export interface ButtonStoryblok {
  label?: string;
  to?: Exclude<MultilinkStoryblok, {linktype?: "email"} | {linktype?: "asset"}>;
  variant?: "" | "primary" | "secondary" | "link" | "navigation" | "download";
  newTab?: boolean;
  icon?: string;
  iconSize?: "" | "s" | "m" | "l" | "xl";
  iconPosition?: "" | "left" | "right";
  color?: "" | "primary" | "secondary" | "accent" | "black" | "white" | "transparent";
  fontColor?: number | string;
  download?: AssetStoryblok;
  component: "Button";
  _uid: string;
  [k: string]: any;
}

Interestingly, the fontColor prop is also the exact same constellation and this gets generated as number | string. This also happens whenever I use this Datasource anywhere else.

Expected behavior: This should consistently result in a type like this:

type colors = "primary" | "secondary" | "white" | "accent" | "transparent"

Steps to reproduce:

  1. Setup datasource Screenshot of the described datasource

  2. Use as data for a single-choice element

  3. Execute type generation npx storyblok pull-components --space={YOUR_ID} && npx storyblok generate-typescript-typedefs --sourceFilePaths ./components.{YOUR_ID}.json --destinationFilePath ./types/storyblok-component-types.d.ts

Other information:

TwoBee avatar Sep 24 '24 13:09 TwoBee