Skip to content

Commit cf0b00d

Browse files
fix: handle dynamic object structs in a T | null union
1 parent 772bd5c commit cf0b00d

File tree

2 files changed

+14
-2
lines changed

2 files changed

+14
-2
lines changed

src/dynamic-param-interfaces.ts

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ import {
66
DetailedObjectType,
77
ParsedDocumentationResult,
88
DetailedFunctionType,
9+
DocumentationTag,
910
} from '@electron/docs-parser';
1011
import chalk from 'chalk';
1112
const debug = d('dynamic-param');
@@ -194,13 +195,16 @@ const flushParamInterfaces = (
194195
return paramPropertyType;
195196
});
196197
}
198+
const isReadonly = (paramProperty.additionalTags || []).includes(DocumentationTag.AVAILABILITY_READONLY)
199+
? 'readonly '
200+
: '';
197201
if (
198202
!Array.isArray(paramProperty.type) &&
199203
paramProperty.type.toLowerCase() === 'function'
200204
) {
201205
// FIXME: functionProp should slot in here perfectly
202206
paramAPI.push(
203-
`${paramProperty.name}${
207+
`${isReadonly}${paramProperty.name}${
204208
utils.isOptional(paramProperty) ? '?' : ''
205209
}: ${utils.genMethodString(
206210
DynamicParamInterfaces,
@@ -211,7 +215,7 @@ const flushParamInterfaces = (
211215
);
212216
} else {
213217
paramAPI.push(
214-
`${paramProperty.name}${utils.isOptional(paramProperty) ? '?' : ''}: ${utils.typify(
218+
`${isReadonly}${paramProperty.name}${utils.isOptional(paramProperty) ? '?' : ''}: ${utils.typify(
215219
paramProperty,
216220
)};`,
217221
);

src/module-declaration.ts

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -335,6 +335,14 @@ export const generateModuleDeclaration = (
335335
let type: string = '';
336336
if (paramType.type === 'Object') {
337337
type = DynamicParamInterfaces.createParamInterface(p as any, '');
338+
} else if (Array.isArray(paramType.type)) {
339+
paramType.type = paramType.type.map(t => t.type !== 'Object' ? t : ({
340+
...t,
341+
type: DynamicParamInterfaces.createParamInterface({
342+
...p,
343+
type: t,
344+
} as any, ''),
345+
}))
338346
}
339347

340348
const isStatic = isStaticVersion ? 'static ' : '';

0 commit comments

Comments
 (0)