Skip to content
This repository was archived by the owner on Mar 31, 2025. It is now read-only.

Commit bc97f0a

Browse files
sonukapoorpetebacondarwin
authored andcommitted
fix(typescript): render type initializations
Previously, the type initializations in a class declaration were removed when the docs are generated. This fixes fixes this issue.
1 parent 1563a74 commit bc97f0a

File tree

5 files changed

+19
-3
lines changed

5 files changed

+19
-3
lines changed
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
export class X<T = any> {
2+
3+
}

typescript/mocks/tsParser/getDeclarationTypeText.test.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ export function testFunction<T>(param1: T[]): number {
66
return 0;
77
}
88

9-
export class TestClass<T> {
9+
export class TestClass<T = any> {
1010
prop1: T[];
1111
prop2 = new OtherClass<T>();
1212
prop3: OtherClass<T, T> = new OtherClass();

typescript/src/api-doc-types/ClassLikeExportDoc.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,10 +6,10 @@ import {
66
HeritageClause,
77
Symbol,
88
SymbolFlags,
9-
symbolName,
109
SyntaxKind,
1110
} from 'typescript';
1211
import { Host } from '../services/ts-host/host';
12+
import { getDeclarationTypeText } from '../services/TsParser/getDeclarationTypeText';
1313
import { getDecorators, ParsedDecorator } from "../services/TsParser/getDecorators";
1414
import { getTypeText } from '../services/TsParser/getTypeText';
1515

@@ -47,7 +47,7 @@ export abstract class ClassLikeExportDoc extends ContainerExportDoc {
4747
const typeParams: string[] = [];
4848
this.symbol.members.forEach((member) => {
4949
if (member.getFlags() & SymbolFlags.TypeParameter) {
50-
typeParams.push(symbolName(member));
50+
member.declarations.forEach(d => typeParams.push(getDeclarationTypeText(d)));
5151
}
5252
});
5353
if (typeParams.length) return `<${typeParams.join(', ')}>`;

typescript/src/processors/readTypeScriptModules/index.spec.ts

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -264,6 +264,17 @@ describe('readTypeScriptModules', () => {
264264
});
265265
});
266266

267+
describe('modules', () => {
268+
it('should include class type parameters', () => {
269+
processor.sourceFiles = [ 'modules.ts'];
270+
const docs: DocCollection = [];
271+
processor.$process(docs);
272+
const typeAliasDoc = docs[1];
273+
expect(typeAliasDoc.docType).toEqual('class');
274+
expect(typeAliasDoc.typeParams).toEqual('<T = any>');
275+
});
276+
})
277+
267278
describe('exported functions', () => {
268279
it('should include type parameters', () => {
269280
processor.sourceFiles = [ 'functions.ts'];

typescript/src/services/TsParser/getDeclarationTypeText.spec.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,10 +23,12 @@ describe('getDeclarationTypeText', () => {
2323
expect(getDeclarationTypeText(testFunction.typeParameters![0])).toEqual('T');
2424

2525
const testClass = getExport('TestClass');
26+
const testClassDeclaration = testClass.getDeclarations()![0] as SignatureDeclaration;
2627
expect(getDeclarationTypeText(testClass.members!.get('prop1' as __String)!.getDeclarations()![0])).toEqual('T[]');
2728
expect(getDeclarationTypeText(testClass.members!.get('prop2' as __String)!.getDeclarations()![0])).toEqual('OtherClass<T>');
2829
expect(getDeclarationTypeText(testClass.members!.get('prop3' as __String)!.getDeclarations()![0])).toEqual('OtherClass<T, T>');
2930
expect(getDeclarationTypeText(testClass.members!.get('method'as __String)!.getDeclarations()![0])).toEqual('T');
31+
expect(getDeclarationTypeText(testClassDeclaration.typeParameters![0])).toEqual('T = any');
3032

3133
function getExport(name: string) {
3234
return moduleExports.find(e => e.name === name)!;

0 commit comments

Comments
 (0)