diff --git a/src/generator.ts b/src/generator.ts index fb8d23b0..28e02d80 100644 --- a/src/generator.ts +++ b/src/generator.ts @@ -174,6 +174,9 @@ function generateRawType(ast: AST, options: Options): string { case 'ARRAY': return (() => { const type = generateType(ast.params, options) + if (!type) { + return 'never' + } return type.endsWith('"') ? '(' + type + ')[]' : type + '[]' })() case 'BOOLEAN': @@ -289,6 +292,9 @@ function generateRawType(ast: AST, options: Options): string { function generateSetOperation(ast: TIntersection | TUnion, options: Options): string { const members = (ast as TUnion).params.map(_ => generateType(_, options)) const separator = ast.type === 'UNION' ? '|' : '&' + if (!members.length) { + return 'never' + } return members.length === 1 ? members[0] : '(' + members.join(' ' + separator + ' ') + ')' } diff --git a/test/__snapshots__/test/test.ts.md b/test/__snapshots__/test/test.ts.md index 28670fb1..4861596f 100644 --- a/test/__snapshots__/test/test.ts.md +++ b/test/__snapshots__/test/test.ts.md @@ -947,6 +947,27 @@ Generated by [AVA](https://avajs.dev). }␊ ` +## emptySet.js + +> Expected output to match snapshot for e2e test: emptySet.js + + `/* eslint-disable */␊ + /**␊ + * This file was automatically generated by json-schema-to-typescript.␊ + * DO NOT MODIFY IT BY HAND. Instead, modify the source JSONSchema file,␊ + * and run json-schema-to-typescript to regenerate this file.␊ + */␊ + ␊ + export interface EmptySet {␊ + a?: never;␊ + b?: never;␊ + c?: never;␊ + d?: {␊ + [k: string]: unknown;␊ + };␊ + }␊ + ` + ## enum.2.js > Expected output to match snapshot for e2e test: enum.2.js diff --git a/test/__snapshots__/test/test.ts.snap b/test/__snapshots__/test/test.ts.snap index 05f2ed95..74d29764 100644 Binary files a/test/__snapshots__/test/test.ts.snap and b/test/__snapshots__/test/test.ts.snap differ diff --git a/test/e2e/emptySet.ts b/test/e2e/emptySet.ts new file mode 100644 index 00000000..5ddbaace --- /dev/null +++ b/test/e2e/emptySet.ts @@ -0,0 +1,10 @@ +export const input = { + type: 'object', + properties: { + a: {anyOf: []}, + b: {oneOf: []}, + c: {allOf: []}, + d: {multipleOf: []}, + }, + additionalProperties: false, +}