storyblok-cli
storyblok-cli copied to clipboard
The generate-typescript-typedefs command throws property.filter_content_type.map is not a function
Current behavior: While running generate-typescript-typedefs command, I am getting the following error.
file:///Users/pawelgrzybek/Desktop/sb/node_modules/.pnpm/[email protected]/node_modules/storyblok/dist/cli.mjs:3309
tsType: `(${property.filter_content_type.map((type2) => __privateMethod(this, _getStoryType, getStoryType_fn).call(this, type2)).join(" | ")} | string )${property.type === "options" ? "[]" : ""}`
^
TypeError: property.filter_content_type.map is not a function
at _GenerateTypesFromJSONSchemas.getPropertyTypeAnnotation_fn (file:///Users/pawelgrzybek/Desktop/sb/node_modules/.pnpm/[email protected]/node_modules/storyblok/dist/cli.mjs:3309:50)
at _GenerateTypesFromJSONSchemas.getTypeAnnotationsForComponentProperties_fn (file:///Users/pawelgrzybek/Desktop/sb/node_modules/.pnpm/[email protected]/node_modules/storyblok/dist/cli.mjs:3240:103)
at async _GenerateTypesFromJSONSchemas.generateTSFile (file:///Users/pawelgrzybek/Desktop/sb/node_modules/.pnpm/[email protected]/node_modules/storyblok/dist/cli.mjs:3166:50)
at async Object.generateTypescriptTypedefs (file:///Users/pawelgrzybek/Desktop/sb/node_modules/.pnpm/[email protected]/node_modules/storyblok/dist/cli.mjs:3465:12)
Expected behavior: To have TS types generated.
Steps to reproduce: Unfortunately I am unable to provide a source file, as it contains structure specific to my company. I am more than happy to share it via private channel. Luckily I managed to narrow the issue down slightly.
https://github.com/storyblok/storyblok-cli/blob/master/src/utils/typescript/generateTypesFromJSONSchema.ts#L347
if (property.source === "internal_stories") {
if (property.filter_content_type) {
return {
tsType: `(${property.filter_content_type
// 👇 - property.filter_content_type can also be a string, and this is the case for my schema
.map((type2) => this.#getStoryType(type2))
// In this case property.type can be `option` or `options`. In case of `options` the type should be an array
.join(" | ")} | string )${property.type === "options" ? "[]" : ""}`,
};
}
}
Other information:
Issue is consistent on Node.js 18 and Node.js 20.