Skip to content

Commit

Permalink
fix: treat an exported namespace as a value export (#285)
Browse files Browse the repository at this point in the history
Co-authored-by: Lucas Treffenstädt <lucas.treffenstaedt@tngtech.com>
  • Loading branch information
mithodin and Lucas Treffenstädt authored Aug 30, 2023
1 parent 3cead14 commit d216307
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 0 deletions.
5 changes: 5 additions & 0 deletions src/transform/ExportsFixer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ export class ExportsFixer {
const exportedName = e.name.text;
const localName = e.propertyName?.text ?? e.name.text;
const kind = types.some(node => node.getText() === localName) && !values.some(node => node.getText() === localName) ? 'type' as const : 'value' as const;
this.DEBUG && (console.log(`export ${localName} as ${exportedName} is a ${kind}`));
return {
exportedName,
localName,
Expand Down Expand Up @@ -96,6 +97,10 @@ export class ExportsFixer {
continue;
}
if (ts.isModuleDeclaration(statement)) {
if (statement.name && ts.isIdentifier(statement.name)) {
this.DEBUG && console.log(`${statement.name.getFullText()} is a value (from module declaration)`);
values.push(statement.name);
}
recurseInto(statement.getChildren());
continue;
}
Expand Down
7 changes: 7 additions & 0 deletions tests/testcases/issue-284/expected.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
interface MyInterface {
a: string;
}
declare namespace MyInterface {
export const b: string;
}
export { MyInterface };
7 changes: 7 additions & 0 deletions tests/testcases/issue-284/index.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
export interface MyInterface {
a: string;
}

export namespace MyInterface {
export const b: string;
}

0 comments on commit d216307

Please sign in to comment.