Skip to content

Commit bb48234

Browse files
committed
fix(types): resolve more types in docs
1 parent 9760599 commit bb48234

2 files changed

Lines changed: 19 additions & 7 deletions

File tree

src/compiler/transpile/datacollection/method-decorator.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import * as d from '../../../declarations';
2-
import { getAttributeTypeInfo, isDecoratorNamed, isMethodWithDecorators, serializeSymbol } from './utils';
2+
import { getAttributeTypeInfo, isDecoratorNamed, isMethodWithDecorators, serializeSymbol, typeToString } from './utils';
33
import { MEMBER_TYPE } from '../../../util/constants';
44
import { validatePublicName } from './reserved-public-members';
55
import ts from 'typescript';
@@ -19,7 +19,7 @@ export function getMethodDecoratorMeta(config: d.Config, diagnostics: d.Diagnost
1919
const methodName = member.name.getText();
2020
const methodSignature = checker.getSignatureFromDeclaration(member);
2121

22-
const flags = ts.TypeFormatFlags.WriteArrowStyleSignature;
22+
const flags = ts.TypeFormatFlags.WriteArrowStyleSignature | ts.TypeFormatFlags.NoTruncation;
2323
const returnType = checker.getReturnTypeOfSignature(methodSignature);
2424
const jsDocReturnTag = ts.getJSDocReturnTag(member);
2525
const typeString = checker.signatureToString(
@@ -61,7 +61,7 @@ export function getMethodDecoratorMeta(config: d.Config, diagnostics: d.Diagnost
6161
jsdoc: {
6262
...serializeSymbol(checker, symbol),
6363
returns: {
64-
type: checker.typeToString(returnType),
64+
type: typeToString(checker, returnType),
6565
documentation: jsDocReturnTag ? jsDocReturnTag.comment : ''
6666
},
6767
parameters: methodSignature.parameters.map(parmSymbol =>
@@ -79,6 +79,6 @@ function isPromise(checker: ts.TypeChecker, type: ts.Type) {
7979
if (type.isUnionOrIntersection()) {
8080
return false;
8181
}
82-
const typeText = checker.typeToString(type);
82+
const typeText = typeToString(checker, type);
8383
return typeText === 'void' || typeText.startsWith('Promise<');
8484
}

src/compiler/transpile/datacollection/utils.ts

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -61,16 +61,28 @@ export function serializeDocsSymbol(checker: ts.TypeChecker, symbol: ts.Symbol):
6161
set.add('boolean');
6262
}
6363

64-
const parts = Array.from(set.keys()).sort();
64+
let parts = Array.from(set.keys()).sort();
65+
if (parts.length > 1) {
66+
parts = parts.map(p => (p.indexOf('=>') >= 0) ? `(${p})` : p);
67+
}
6568
if (parts.length > 20) {
66-
return checker.typeToString(type);
69+
return typeToString(checker, type);
6770
} else {
6871
return parts.join(' | ');
6972
}
7073
}
7174

75+
const TYPE_FORMAT_FLAGS =
76+
ts.TypeFormatFlags.NoTruncation |
77+
ts.TypeFormatFlags.InTypeAlias |
78+
ts.TypeFormatFlags.InElementType;
79+
80+
export function typeToString(checker: ts.TypeChecker, type: ts.Type) {
81+
return checker.typeToString(type, undefined, TYPE_FORMAT_FLAGS);
82+
}
83+
7284
export function parseDocsType(checker: ts.TypeChecker, type: ts.Type, parts: Set<string>) {
73-
const text = checker.typeToString(type);
85+
const text = typeToString(checker, type);
7486
if (type.isUnion()) {
7587
(type as ts.UnionType).types.forEach(t => {
7688
parseDocsType(checker, t, parts);

0 commit comments

Comments
 (0)