chore(doc-gen): render optional members correctly
Partially Closes #2849
This commit is contained in:
parent
561b78a5b3
commit
ef3cc8e6eb
|
@ -31,7 +31,7 @@ p.location-badge.
|
|||
|
||||
{%- for member in doc.members %}{% if not member.private %}
|
||||
.l-sub-section
|
||||
h3 {$ member.name $}
|
||||
h3 {$ member.name $}{% if member.optional %}?{% endif %}
|
||||
|
||||
{% if member.parameters %}
|
||||
pre.prettyprint
|
||||
|
|
|
@ -0,0 +1,4 @@
|
|||
export interface MyInterface {
|
||||
optionalProperty? : string,
|
||||
(param: string) : string
|
||||
}
|
|
@ -212,6 +212,10 @@ module.exports = function readTypeScriptModules(tsParser, readFilesProcessor, mo
|
|||
memberDoc.returnType = getReturnType(typeChecker, memberSymbol);
|
||||
}
|
||||
|
||||
if(memberSymbol.flags & ts.SymbolFlags.Optional) {
|
||||
memberDoc.optional = true;
|
||||
}
|
||||
|
||||
return memberDoc;
|
||||
}
|
||||
|
||||
|
|
|
@ -45,6 +45,22 @@ describe('readTypeScriptModules', function() {
|
|||
});
|
||||
|
||||
|
||||
describe('interfaces', function() {
|
||||
|
||||
it('should mark optional properties', function() {
|
||||
processor.sourceFiles = [ 'interfaces.ts'];
|
||||
var docs = [];
|
||||
processor.$process(docs);
|
||||
|
||||
var moduleDoc = docs[0];
|
||||
var exportedInterface = moduleDoc.exports[0];
|
||||
var member = exportedInterface.members[0];
|
||||
expect(member.name).toEqual('optionalProperty');
|
||||
expect(member.optional).toEqual(true);
|
||||
});
|
||||
});
|
||||
|
||||
|
||||
describe('ordering of members', function() {
|
||||
it('should order class members in order of appearance (by default)', function() {
|
||||
processor.sourceFiles = ['orderingOfMembers.ts'];
|
||||
|
|
|
@ -23,7 +23,9 @@ defined in {$ githubViewLink(doc) $}
|
|||
|
||||
{%- for member in doc.members %}{% if not member.private %}
|
||||
<section class="member">
|
||||
<h1 id="{$ member.name $}" class="name">{$ member.name $}{$ paramList(member.params) $}</h1>
|
||||
<h1 id="{$ member.name $}" class="name">
|
||||
{$ member.name $}{% if member.optional %}?{% endif %}{$ paramList(member.params) $}
|
||||
</h1>
|
||||
{% marked %}
|
||||
{$ member.description $}
|
||||
{% endmarked %}
|
||||
|
|
|
@ -29,6 +29,7 @@ declare module "{$ module.id $}" {
|
|||
{%- for member in export.members -%}
|
||||
{$ commentBlock(member, 5) $}
|
||||
{$ member.name $}
|
||||
{%- if member.optional %}?{% endif -%}
|
||||
{%- if member.parameters %}({% for param in member.parameters %}{$ param $}{% if not loop.last %}, {% endif %}{% endfor %}){%- endif %}
|
||||
{%- if member.returnType %}: {$ member.returnType $}{%- else -%}: any{% endif -%}
|
||||
;
|
||||
|
|
Loading…
Reference in New Issue