Skip to content

Commit

Permalink
fix(boolean): generate type boolean instead of `boolean | undefined…
Browse files Browse the repository at this point in the history
…` for boolean fields

Refs: dohomi#73
  • Loading branch information
Xaver Fleer committed Sep 18, 2024
1 parent 0558910 commit d675acd
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 5 deletions.
6 changes: 2 additions & 4 deletions src/index.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -43,13 +43,11 @@ describe("storyblokToTypescript", () => {
const types = await storyblokToTypescript({
componentsJson: makeSBComponent({
myField: { type: "boolean" },
myRequiredField: { type: "boolean", required: true },
}),
});
const mainType = prepareString(types[2]);
const expectation = makeExpectString(`
myField?: boolean;
myRequiredField: boolean;
myField: boolean;
`);

expect(mainType).toBe(expectation);
Expand Down Expand Up @@ -206,7 +204,7 @@ describe("storyblokToTypescript", () => {
copyright?: string;
fieldtype?: string;
meta_data?: null|{[k:string]:any;};
is_external_url?:boolean;
is_external_url: boolean;
[k: string]: any;
}`);

Expand Down
5 changes: 4 additions & 1 deletion src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,10 @@ export default async function storyblokToTypescript({
}
const requiredFields = ['_uid', 'component']
Object.keys(values.schema).forEach(key => {
if (values.schema[key].required) {
if (
values.schema[key].required ||
values.schema[key].type === "boolean"
) {
requiredFields.push(key)
}
})
Expand Down

0 comments on commit d675acd

Please sign in to comment.