Skip to content

Commit 669d31c

Browse files
fix: prefix promise types where appropriate (#234)
* Revert "fix: do not prefix promise inner types (#227)" This reverts commit 9560079. * fix: prefix promise types where appropriate
1 parent 275007e commit 669d31c

File tree

1 file changed

+14
-1
lines changed

1 file changed

+14
-1
lines changed

src/utils.ts

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -95,6 +95,19 @@ export const wrapComment = (comment: string, additionalTags: DocumentationTag[]
9595
return result.concat(' */');
9696
};
9797

98+
const prefixTypeForSafety = (type: string) => {
99+
if (
100+
type !== 'Object' &&
101+
typeof type === 'string' &&
102+
!isPrimitive(type) &&
103+
!isBuiltIn(type) &&
104+
!/\(\| /gi.test(type)
105+
) {
106+
return `Electron.${type}`;
107+
}
108+
return type;
109+
};
110+
98111
export const typify = (
99112
type: TypeInformation | TypeInformation[],
100113
maybeInnerReturnTypeName?: string,
@@ -211,7 +224,7 @@ export const typify = (
211224
return '(() => void)';
212225
case 'promise':
213226
if (innerTypes) {
214-
return `Promise<${typify(innerTypes[0])}>`;
227+
return `Promise<${prefixTypeForSafety(typify(innerTypes[0]))}>`;
215228
}
216229
throw new Error('Promise with missing inner type');
217230
case 'record':

0 commit comments

Comments
 (0)