Skip to content

Commit

Permalink
fix: infinite loop on empty record (#34)
Browse files Browse the repository at this point in the history
  • Loading branch information
Mikalai Ziuz committed Apr 10, 2021
1 parent 321fffe commit 5596de4
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 0 deletions.
8 changes: 8 additions & 0 deletions src/__tests__/main.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,13 @@ describe('runtype generation', () => {
],
},
},
{
name: 'emptyObject',
type: {
kind: 'record',
fields: [],
},
},
],
},
},
Expand Down Expand Up @@ -126,6 +133,7 @@ describe('runtype generation', () => {
rt.Literal(\\"last\\")
),
}),
emptyObject: rt.Record({}),
});
"
`);
Expand Down
5 changes: 5 additions & 0 deletions src/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -208,6 +208,11 @@ export function groupFieldKinds(
}

function writeRecordType(w: CodeWriter, node: RecordType) {
if (node.fields.length === 0) {
w.write('rt.Record({})');
return;
}

const fieldKinds = groupFieldKinds(node.fields);
const hasMultiple = fieldKinds.length > 1;
w.conditionalWrite(hasMultiple, 'rt.Intersect(');
Expand Down

0 comments on commit 5596de4

Please sign in to comment.