Skip to content

Commit 8269bce

Browse files
authored
fix: ensure Electron.Utility property exists (#247)
* fix: ensure Electron.Utility property exists Added in #246, the Utility namespace currently has no concrete values in it on electron/electron@main. This change ensures Electron.Utility is available as a property even when the namespace has no values. * fix: only set Utility property if namespace empty If the Utility namespace has concrete values and the const Utility property is set it causes `error TS2300: Duplicate identifier 'Utility'.` This tracks whether any values are added to the Utility namespace and only sets the property workaround if there are none.
1 parent 4b67b76 commit 8269bce

File tree

1 file changed

+12
-1
lines changed

1 file changed

+12
-1
lines changed

src/primary-interfaces.ts

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,8 @@ export const generatePrimaryInterfaces = (
3333
}
3434
};
3535

36+
let utilityNamespaceHasValues = false;
37+
3638
API.forEach((module, index) => {
3739
if (module.name === 'process') return;
3840
let TargetNamespace;
@@ -102,10 +104,19 @@ export const generatePrimaryInterfaces = (
102104
);
103105
TargetNamespace.push(...declarations);
104106
CrossProcessExportsNamespace.push(...declarations);
105-
if (module.process.utility) UtilityNamespace.push(...declarations);
107+
if (module.process.utility) {
108+
UtilityNamespace.push(...declarations);
109+
if (newConstDeclarations.length > 0) {
110+
utilityNamespaceHasValues = true;
111+
}
112+
}
106113
}
107114
});
108115

116+
if (!utilityNamespaceHasValues) {
117+
constDeclarations.push('const Utility: {};');
118+
}
119+
109120
for (const interfaceKey of interfaceKeys) {
110121
const alias = ` type ${interfaceKey} = Electron.${interfaceKey}`;
111122
CommonNamespace.push(alias);

0 commit comments

Comments
 (0)