Skip to content

Commit fa913c4

Browse files
feat: add support for Record<A, B> (#134)
1 parent 474b97c commit fa913c4

File tree

3 files changed

+13
-7
lines changed

3 files changed

+13
-7
lines changed

lib/utils.js

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,7 @@ const typify = (type) => {
7474
case 'float[]':
7575
return 'number[]'
7676
case 'array': {
77-
if (innerType) return `Array<${innerType}>`
77+
if (innerType) return `Array<${typify(innerType[0])}>`
7878
debug('Untyped "Array" as return type'.yellow)
7979
return 'any[]'
8080
}
@@ -105,10 +105,16 @@ const typify = (type) => {
105105
return '(() => void)'
106106
case 'promise':
107107
if (innerType) {
108-
return `Promise<${innerType}>`
108+
return `Promise<${typify(innerType[0])}>`
109109
}
110110
debug('Promise with missing inner type, defaulting to any')
111111
return 'Promise<any>'
112+
case 'record':
113+
if (innerType && innerType.length === 2) {
114+
return `Record<${typify(innerType[0])}, ${typify(innerType[1])}>`
115+
}
116+
debug('Record with missing inner types, default to any')
117+
return 'Record<any, any>'
112118
case 'url':
113119
return 'string'
114120
case 'touchbaritem':
@@ -196,7 +202,7 @@ const genMethodString = (paramInterfaces, module, moduleMethod, parameters, retu
196202
if (Array.isArray(param.type)) {
197203
param.type = param.type.map((paramType) => {
198204
if (paramType.typeName === 'Function' && param.parameters) {
199-
return Object.assign({}, paramType, { typeName: genMethodString(paramInterfaces, module, moduleMethod, param.parameters, param.returns || paramType.innerType) })
205+
return Object.assign({}, paramType, { typeName: genMethodString(paramInterfaces, module, moduleMethod, param.parameters, param.returns || (paramType.innerType && paramType.innerType[0])) })
200206
}
201207
return paramType
202208
})

package-lock.json

Lines changed: 3 additions & 3 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@
3838
"colors": "^1.1.2",
3939
"debug": "^2.6.3",
4040
"electron-docs": "^2.0.0",
41-
"electron-docs-linter": "^2.5.0",
41+
"electron-docs-linter": "^3.0.0",
4242
"lodash": "^4.17.11",
4343
"mkdirp": "^0.5.1",
4444
"rimraf": "^2.5.4",

0 commit comments

Comments
 (0)