Skip to content

Commit

Permalink
chore: parse complex union types like 'foo' | string correctly for …
Browse files Browse the repository at this point in the history
…documentation
  • Loading branch information
maxokorokov committed Jan 13, 2020
1 parent 31402a3 commit b97bd9f
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 4 deletions.
2 changes: 1 addition & 1 deletion misc/api-doc-test-cases/interface-with-properties.ts
Expand Up @@ -16,5 +16,5 @@ export interface NgbModalOptions {
/**
* Size of a new modal window.
*/
size?: 'sm' | 'lg' | 'xl';
size?: 'sm' | 'lg' | 'xl' | string;
}
4 changes: 2 additions & 2 deletions misc/api-doc.spec.ts
Expand Up @@ -171,7 +171,7 @@ describe('APIDocVisitor', () => {
expect(interfaceDocs.properties[0].name).toBe('backdrop');
expect(interfaceDocs.properties[0].description)
.toContain('Weather a backdrop element should be created for a given modal (true by default).');
expect(interfaceDocs.properties[0].type).toBe('boolean | "static"');
expect(interfaceDocs.properties[0].type).toBe(`boolean | 'static'`);
expect(interfaceDocs.properties[0].defaultValue).toBeUndefined();

expect(interfaceDocs.properties[1].name).toBe('keyboard');
Expand All @@ -182,7 +182,7 @@ describe('APIDocVisitor', () => {

expect(interfaceDocs.properties[2].name).toBe('size');
expect(interfaceDocs.properties[2].description).toBe('<p>Size of a new modal window.</p>');
expect(interfaceDocs.properties[2].type).toBe('"sm" | "lg" | "xl"');
expect(interfaceDocs.properties[2].type).toBe(`'sm' | 'lg' | 'xl' | string`);
expect(interfaceDocs.properties[2].defaultValue).toBeUndefined();
});

Expand Down
8 changes: 7 additions & 1 deletion misc/api-doc.ts
Expand Up @@ -325,7 +325,13 @@ class APIDocVisitor {
};
}

visitType(node) { return node ? this.typeChecker.typeToString(this.typeChecker.getTypeAtLocation(node)) : 'void'; }
visitType(node) {
if (node && node.type) {
return node.type.getText();
}

return node ? this.typeChecker.typeToString(this.typeChecker.getTypeAtLocation(node)) : 'void';
}

isDirectiveDecorator(decorator) {
const decoratorIdentifierText = decorator.expression.expression.text;
Expand Down

0 comments on commit b97bd9f

Please sign in to comment.