Skip to content

Commit

Permalink
Added correcting types for abstract classes if they aren't exported
Browse files Browse the repository at this point in the history
Fixes #198
  • Loading branch information
timocov committed Apr 19, 2022
1 parent 2de08d5 commit 9461805
Show file tree
Hide file tree
Showing 5 changed files with 19 additions and 1 deletion.
2 changes: 1 addition & 1 deletion src/generate-output.ts
Original file line number Diff line number Diff line change
Expand Up @@ -144,7 +144,7 @@ function needAddDeclareKeyword(statement: ts.Statement, nodeText: string): boole
// for some reason TypeScript allows to do not write `declare` keyword for ClassDeclaration, FunctionDeclaration and VariableDeclaration
// if it already has `export` keyword - so we need to add it
// to avoid TS1046: Top-level declarations in .d.ts files must start with either a 'declare' or 'export' modifier.
if (ts.isClassDeclaration(statement) && /^class\b/.test(nodeText)) {
if (ts.isClassDeclaration(statement) && (/^class\b/.test(nodeText) || /^abstract\b/.test(nodeText))) {
return true;
}

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
export abstract class AbstractClass {
}
5 changes: 5 additions & 0 deletions tests/e2e/test-cases/non-exported-abstract-class/config.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
import { TestCaseConfig } from '../test-case-config';

const config: TestCaseConfig = {};

export = config;
5 changes: 5 additions & 0 deletions tests/e2e/test-cases/non-exported-abstract-class/input.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
import { AbstractClass } from './abstract-class';

export class NormalClass extends AbstractClass {

}
6 changes: 6 additions & 0 deletions tests/e2e/test-cases/non-exported-abstract-class/output.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
declare abstract class AbstractClass {
}
export declare class NormalClass extends AbstractClass {
}

export {};

0 comments on commit 9461805

Please sign in to comment.