Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Don't change name of interface/class #336

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions src/generate-output.ts
Original file line number Diff line number Diff line change
Expand Up @@ -231,6 +231,13 @@ function getStatementText(statement: ts.Statement, includeSortingValue: boolean,
return node;
}

if (ts.isIdentifier(node) && (node.parent as ts.NamedDeclaration).name === node && (
ts.isInterfaceDeclaration(node.parent) ||
ts.isClassDeclaration(node.parent)
)) {
return node;
}

return recreateEntityName(node, helpers);
}
}
Expand Down
3 changes: 3 additions & 0 deletions tests/e2e/test-cases/names-collision-with-globals/config.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
import { TestCaseConfig } from '../test-case-config';

const config: TestCaseConfig = {
output: {
inlineDeclareExternals: true
}
};

export = config;
14 changes: 14 additions & 0 deletions tests/e2e/test-cases/names-collision-with-globals/input.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { Date as LocalDate, Promise as LocalPromise } from './local-types';
import { BaseEncodingOptions as Alias1, BigIntOptions as Alias2 } from 'node:fs';

export interface Int {
localD: LocalDate;
Expand All @@ -7,3 +8,16 @@ export interface Int {
localP: LocalPromise;
globalP: Promise<number>;
}

export interface Interface1 extends Alias1 {}
export interface Interface2 extends Alias2 {}

declare module 'node:fs' {
interface BaseEncodingOptions {
newField: string;
}

class BigIntOptions {
newField: string;
}
}
14 changes: 14 additions & 0 deletions tests/e2e/test-cases/names-collision-with-globals/output.d.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import { BaseEncodingOptions as Alias1, BigIntOptions as Alias2 } from 'node:fs';

interface Promise$3 {
}
interface Date$2 {
Expand All @@ -8,5 +10,17 @@ export interface Int {
localP: Promise$3;
globalP: Promise<number>;
}
export interface Interface1 extends Alias1 {
}
export interface Interface2 extends Alias2 {
}
declare module "node:fs" {
interface BaseEncodingOptions {
newField: string;
}
class BigIntOptions {
newField: string;
}
}

export {};
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
{
"extends": "../tsconfig.json",
"compilerOptions": {
"types": ["node"]
}
}