Skip to content

Commit e071b1d

Browse files
committed
feat,fix(type-doc): feat/fit new method type implement
1 parent 088f48d commit e071b1d

File tree

1 file changed

+29
-1
lines changed

1 file changed

+29
-1
lines changed

src/typedoc.parser/parsers/methods.parser.ts

+29-1
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ export class MethodsParser {
2424
platform: null,
2525
name: obj[CO.name],
2626
type: this.getType(obj),
27+
// type: ['string'],
2728
isStatic: this.isStatic(obj),
2829
shortDescription: this.getShortDescription(obj),
2930
description: this.getDescription(obj)
@@ -63,6 +64,8 @@ export class MethodsParser {
6364
return this.parseReference(obj);
6465
} else if (this.isArray(obj[CO.type])) {
6566
return this.parseArray(obj);
67+
} else if (this.isTypeParameter(obj[CO.type])) {
68+
return this.parseTypeParameter(obj);
6669
}
6770
}
6871

@@ -126,8 +129,11 @@ export class MethodsParser {
126129
parseReflection(obj: any) {
127130
if (obj[CO.type][CO.declaration][CO.children] && obj[CO.type][CO.declaration][CO.children].length !== 0) {
128131
return this.parseTypeFromReflectionChildren(obj);
129-
} else {
132+
} else if(obj[CO.type][CO.declaration][CO.indexSignature] &&
133+
obj[CO.type][CO.declaration][CO.indexSignature].length !== 0) {
130134
return this.parseTypeFromReflectionIndexSignature(obj);
135+
} else {
136+
return this.parseTypeFromSignature(obj);
131137
}
132138
}
133139

@@ -156,6 +162,24 @@ export class MethodsParser {
156162
.replace(/:/g, ': ');
157163
}
158164

165+
parseTypeFromSignature(obj: any) {
166+
const mainReturnedType: any = this.determineType(obj[CO.type][CO.declaration][CO.signatures][0]);
167+
let parameters: any[] = [];
168+
obj[CO.type][CO.declaration][CO.signatures][0][CO.parameters].forEach((item: any) => {
169+
parameters.push(item[CO.name] + ': ' + this.determineType(item));
170+
});
171+
let returnedTypePrepared: string = '';
172+
parameters.forEach((item: any) => {
173+
returnedTypePrepared += item.toString() + ', ';
174+
});
175+
176+
return ('(' + returnedTypePrepared + ') => ' + mainReturnedType).replace(/, \)/g, ')');
177+
}
178+
179+
parseTypeParameter(obj: any) {
180+
return obj[CO.type][CO.name];
181+
}
182+
159183
parseArray(obj: any) {
160184
return obj[CO.type][CO.elementType][CO.name] + '[]';
161185
}
@@ -195,4 +219,8 @@ export class MethodsParser {
195219
isArray(obj: any) {
196220
return obj[CO.type] === 'array';
197221
}
222+
223+
isTypeParameter(obj: any) {
224+
return obj[CO.type] === 'typeParameter';
225+
}
198226
}

0 commit comments

Comments
 (0)