storyblok-generate-ts icon indicating copy to clipboard operation
storyblok-generate-ts copied to clipboard

On custom SB type generate - includes import of StoryBloKStory?

Open Galanthus opened this issue 5 months ago • 1 comments

I have this:

const storyblokToTypescript = require("storyblok-generate-ts").default

storyblokToTypescript({
  componentsJson: require("./components.xxxxx.json"),
  path: __dirname + "/sb-types.ts",
  titlePrefix: "nc",
  compilerOptions: {
    additionalProperties: false,
    unknownAny: false,
  },
})

It generates:

import { StoryblokStory } from "storyblok-generate-ts"

export interface NcfeatureStoryblok {
  name?: string
  _uid: string
  component: "feature"
}

export interface NcgridStoryblok {
  columns?: (
    | NcfeatureStoryblok
    | NcgridStoryblok
    | NcpageStoryblok
    | NcteaserStoryblok
  )[]
  _uid: string
  component: "grid"
}

export interface NcpageStoryblok {
  body?: (
    | NcfeatureStoryblok
    | NcgridStoryblok
    | NcpageStoryblok
    | NcteaserStoryblok
  )[]
  _uid: string
  component: "page"
  uuid?: string
}

export interface NcteaserStoryblok {
  headline?: string
  _uid: string
  component: "teaser"
}

How to exclude the import?

Galanthus avatar Mar 06 '24 22:03 Galanthus

as soon you'd use single/multiple option fields or a bunch of other Storyblok features this type gets mandatory. There could be an option for very simple schema to leave it out, but I am currently busy with other things. Feel free to open a PR if you want to leave the type out

dohomi avatar Mar 07 '24 00:03 dohomi