Skip to content

Commit 82ddba9

Browse files
fix: export type alises for process-specific classes just not by value
1 parent fdb1937 commit 82ddba9

File tree

1 file changed

+17
-12
lines changed

1 file changed

+17
-12
lines changed

src/master-interfaces.ts

Lines changed: 17 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -40,11 +40,13 @@ export const generateMasterInterfaces = (
4040
// We must be a structure or something
4141
return;
4242
}
43-
const moduleString =
44-
isClass && module.process.exported
43+
const moduleString = isClass
44+
? module.process.exported
4545
? ` class ${_.upperFirst(module.name)} extends Electron.${_.upperFirst(module.name)} {}`
46-
: '';
46+
: ` type ${_.upperFirst(module.name)} = Electron.${_.upperFirst(module.name)}`
47+
: '';
4748
const newConstDeclarations: string[] = [];
49+
const newTypeAliases: string[] = [];
4850
// In the case where this module is actually the static methods on a Class type
4951
const isModuleButActuallyStaticClass = API.some(
5052
(tModule, tIndex) =>
@@ -63,6 +65,9 @@ export const generateMasterInterfaces = (
6365
newConstDeclarations.push(
6466
`const ${classify(module.name)}: typeof ${_.upperFirst(module.name)};`,
6567
);
68+
newTypeAliases.push(
69+
`type ${_.upperFirst(module.name)} = Electron.${_.upperFirst(module.name)};`,
70+
);
6671
} else {
6772
newConstDeclarations.push(
6873
`const ${classify(module.name)}: ${_.upperFirst(module.name)};`,
@@ -71,14 +76,12 @@ export const generateMasterInterfaces = (
7176
}
7277
}
7378
constDeclarations.push(...newConstDeclarations);
74-
if (module.process.exported) {
75-
if (module.process.main && module.process.renderer) {
76-
TargetNamespace = CommonNamespace;
77-
} else if (module.process.main) {
78-
TargetNamespace = MainNamespace;
79-
} else if (module.process.renderer) {
80-
TargetNamespace = RendererNamespace;
81-
}
79+
if (module.process.main && module.process.renderer) {
80+
TargetNamespace = CommonNamespace;
81+
} else if (module.process.main) {
82+
TargetNamespace = MainNamespace;
83+
} else if (module.process.renderer) {
84+
TargetNamespace = RendererNamespace;
8285
}
8386
if (
8487
module.process.main &&
@@ -98,7 +101,9 @@ export const generateMasterInterfaces = (
98101
if (moduleString) CrossProcessExportsNamespace.push(moduleString);
99102
}
100103
EMRI[classify(module.name).toLowerCase()] = true;
101-
const declarations = newConstDeclarations.map(s => ` ${s.substr(0, s.length - 1)}`);
104+
const declarations = [...newConstDeclarations, ...newTypeAliases].map(
105+
s => ` ${s.substr(0, s.length - 1)}`,
106+
);
102107
TargetNamespace.push(...declarations);
103108
CrossProcessExportsNamespace.push(...declarations);
104109
}

0 commit comments

Comments
 (0)