Skip to content

Commit 72522b4

Browse files
author
k.golikov
committed
Some fixes / improvements
1 parent 1fdea10 commit 72522b4

File tree

2 files changed

+11
-8
lines changed

2 files changed

+11
-8
lines changed

src/pages/jsonToTypeScriptPage/utils/getAllTypeScriptTypeDeclarations.ts

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,13 @@ import getTypeScriptTypeDeclaration from './getTypeScriptTypeDeclaration';
44
import ExportType from '../types/ExportType';
55

66
const getAllTypeScriptTypeDeclarations = (type: TypeScriptType, name: string, exportType?: ExportType) => {
7-
return getAllTypeScriptTypeDeclarableTypes(type)
7+
const declarableTypes = getAllTypeScriptTypeDeclarableTypes(type);
8+
9+
if (declarableTypes.length === 0) {
10+
return getTypeScriptTypeDeclaration(type, name, exportType);
11+
}
12+
13+
return declarableTypes
814
.map((declarable) => getTypeScriptTypeDeclaration(declarable as TypeScriptType, name, exportType))
915
.join('\n\n');
1016
};
Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,14 @@
11
import { TypeScriptType } from '../types/typescript';
2-
import { isString } from 'lodash';
2+
import { isObject } from 'lodash';
33
import ExportType from '../types/ExportType';
4+
import getTypeScriptTypeReference from './getTypeScriptTypeReference';
45

56
const getTypeScriptTypeDeclaration = (type: TypeScriptType, name: string, exportType?: ExportType): string => {
6-
if (isString(type)) {
7-
return `type ${name} = ${type};`;
8-
}
9-
10-
if ('stringifyDeclaration' in type) {
7+
if (isObject(type) && 'stringifyDeclaration' in type) {
118
return type.stringifyDeclaration(exportType);
129
}
1310

14-
return '';
11+
return `type ${name} = ${getTypeScriptTypeReference(type)};`;
1512
};
1613

1714
export default getTypeScriptTypeDeclaration;

0 commit comments

Comments
 (0)