Skip to content

Commit 515fcaf

Browse files
feat: add support for inner type objects
1 parent b065807 commit 515fcaf

File tree

3 files changed

+105
-96
lines changed

3 files changed

+105
-96
lines changed

lib/module-declaration.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -142,7 +142,7 @@ const generateModuleDeclaration = (module, index, API) => {
142142

143143
const paramString = utils.genMethodString(paramInterfaces, module, moduleMethod, moduleMethod.parameters, moduleMethod.returns, false, module.name === 'process' ? 'Electron.' : '')
144144

145-
moduleAPI.push(`${prefix}${moduleMethod.name}(${paramString})${moduleMethod.name === 'constructor' ? '' : `: ${utils.typify(returnType)}`};`)
145+
moduleAPI.push(`${prefix}${moduleMethod.name}(${paramString})${moduleMethod.name === 'constructor' ? '' : `: ${utils.typify(returnType, `${_.upperFirst(moduleMethod.name)}ReturnValue`)}`};`)
146146
}
147147

148148
// Class constructor

lib/utils.js

Lines changed: 21 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,14 @@ const _ = require('lodash')
44
const debug = require('debug')('utils')
55
require('colors')
66

7+
let paramInterfaces
8+
const lazyParamInterfaces = () => {
9+
if (!paramInterfaces) {
10+
paramInterfaces = require('./dynamic-param-interfaces')
11+
}
12+
return paramInterfaces
13+
}
14+
715
const extendArray = (arr1, arr2) => Array.prototype.push.apply(arr1, arr2) && arr1
816

917
const wrapComment = (comment) => {
@@ -32,7 +40,7 @@ const prefixTypeForSafety = (type) => {
3240
return type
3341
}
3442

35-
const typify = (type) => {
43+
const typify = (type, maybeInnerReturnTypeName) => {
3644
// Capture some weird edge cases
3745
const originalType = type
3846
if (type.type && typeof type.type === 'object') {
@@ -66,6 +74,18 @@ const typify = (type) => {
6674

6775
if (type.innerType) {
6876
innerType = type.innerType
77+
if (type.innerType && type.properties) {
78+
innerType = [
79+
lazyParamInterfaces().createParamInterface(
80+
{
81+
...type,
82+
type: 'Object',
83+
name: ''
84+
},
85+
maybeInnerReturnTypeName
86+
)
87+
]
88+
}
6989
}
7090

7191
type = newType

0 commit comments

Comments
 (0)