Skip to content

Commit 16464fc

Browse files
committed
generate typeof import() instead of regular import statements to ensure typescript does not treat the generated type declaration as a module
treating it as a module means interfaces do not merge with interfaces from other type declarations
1 parent 8640bfc commit 16464fc

File tree

1 file changed

+4
-4
lines changed

1 file changed

+4
-4
lines changed

src/generateTypeDeclaration.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -50,15 +50,15 @@ export async function generateTypeDeclaration(sourceDirectory: string, hackmudPa
5050
let o = ``
5151

5252
for (const script of wildScripts)
53-
o += `import $${script}$ from "${sourceDirectory}/${script}"\n`
53+
o += `type $${script}$ = typeof import("${sourceDirectory}/${script}").default\n`
5454

5555
o += `\n`
5656

5757
for (const user in allScripts) {
5858
const scripts = allScripts[user]!
5959

6060
for (const script of scripts)
61-
o += `import $${user}$${script}$ from "${sourceDirectory}/${user}/${script}"\n`
61+
o += `type $${user}$${script}$ = typeof import("${sourceDirectory}/${user}/${script}").default\n`
6262
}
6363

6464
// TODO detect security level and generate apropriate code
@@ -77,7 +77,7 @@ type WildFullsec = Record<string, () => ScriptFailure> & {
7777
`
7878

7979
for (const script of wildScripts)
80-
o += `\t${script}: Subscript<typeof $${script}$>\n`
80+
o += `\t${script}: Subscript<$${script}$>\n`
8181

8282
for (const script of wildAnyScripts)
8383
o += `\t${script}: (...args: any) => any\n`
@@ -96,7 +96,7 @@ type WildFullsec = Record<string, () => ScriptFailure> & {
9696

9797
if (scripts) {
9898
for (const script of scripts)
99-
o += `\t\t${script}: Subscript<typeof $${user}$${script}$>\n`
99+
o += `\t\t${script}: Subscript<$${user}$${script}$>\n`
100100
}
101101

102102
if (anyScripts) {

0 commit comments

Comments
 (0)