diff --git a/docs/dgeni-package/mocks/readTypeScriptModules/interfaces.ts b/docs/dgeni-package/mocks/readTypeScriptModules/interfaces.ts index 7a0de50548..a2d4be4fec 100644 --- a/docs/dgeni-package/mocks/readTypeScriptModules/interfaces.ts +++ b/docs/dgeni-package/mocks/readTypeScriptModules/interfaces.ts @@ -1,5 +1,5 @@ export interface MyInterface { optionalProperty? : string - (param: string) : string + >(param: T) : U new (param: number) : MyInterface } \ No newline at end of file diff --git a/docs/dgeni-package/processors/readTypeScriptModules.js b/docs/dgeni-package/processors/readTypeScriptModules.js index bf26c837aa..0e9f310f1f 100644 --- a/docs/dgeni-package/processors/readTypeScriptModules.js +++ b/docs/dgeni-package/processors/readTypeScriptModules.js @@ -202,7 +202,22 @@ module.exports = function readTypeScriptModules(tsParser, readFilesProcessor, mo location: getLocation(memberSymbol) }; - if (memberSymbol.flags & (ts.SymbolFlags.Method | ts.SymbolFlags.Signature)) { + memberDoc.typeParameters = getTypeParameters(typeChecker, memberSymbol); + + if(memberSymbol.flags & (ts.SymbolFlags.Signature) ) { + memberDoc.parameters = getParameters(typeChecker, memberSymbol); + memberDoc.returnType = getReturnType(typeChecker, memberSymbol); + switch(memberDoc.name) { + case '__call': + memberDoc.name = ''; + break; + case '__new': + memberDoc.name = 'new'; + break; + } + } + + if (memberSymbol.flags & ts.SymbolFlags.Method) { // NOTE: we use the property name `parameters` here so we don't conflict // with the `params` property that will be updated by dgeni reading the // `@param` tags from the docs @@ -214,7 +229,7 @@ module.exports = function readTypeScriptModules(tsParser, readFilesProcessor, mo memberDoc.name = 'constructor'; } - if(memberSymbol.flags & (ts.SymbolFlags.Value | ts.SymbolFlags.Signature) ) { + if(memberSymbol.flags & ts.SymbolFlags.Value) { memberDoc.returnType = getReturnType(typeChecker, memberSymbol); } @@ -248,6 +263,16 @@ module.exports = function readTypeScriptModules(tsParser, readFilesProcessor, mo }); } + function getTypeParameters(typeChecker, symbol) { + var declaration = symbol.valueDeclaration || symbol.declarations[0]; + var sourceFile = ts.getSourceFileOfNode(declaration); + if (!declaration.typeParameters) return; + var typeParams = declaration.typeParameters.map(function(type) { + return getText(sourceFile, type).trim(); + }); + return typeParams; + } + function getReturnType(typeChecker, symbol) { var declaration = symbol.valueDeclaration || symbol.declarations[0]; var sourceFile = ts.getSourceFileOfNode(declaration); diff --git a/docs/dgeni-package/processors/readTypeScriptModules.spec.js b/docs/dgeni-package/processors/readTypeScriptModules.spec.js index 85354d8e10..53d959c70c 100644 --- a/docs/dgeni-package/processors/readTypeScriptModules.spec.js +++ b/docs/dgeni-package/processors/readTypeScriptModules.spec.js @@ -67,12 +67,14 @@ describe('readTypeScriptModules', function() { var moduleDoc = docs[0]; var exportedInterface = moduleDoc.exports[0]; + expect(exportedInterface.callMember).toBeDefined(); - expect(exportedInterface.callMember.parameters).toBeDefined(); - expect(exportedInterface.callMember.returnType).toBeDefined(); + expect(exportedInterface.callMember.parameters).toEqual(['param: T']); + expect(exportedInterface.callMember.returnType).toEqual('U'); + expect(exportedInterface.callMember.typeParameters).toEqual(['T', 'U extends Findable']); expect(exportedInterface.newMember).toBeDefined(); - expect(exportedInterface.newMember.parameters).toBeDefined(); - expect(exportedInterface.newMember.returnType).toBeDefined(); + expect(exportedInterface.newMember.parameters).toEqual(['param: number']); + expect(exportedInterface.newMember.returnType).toEqual('MyInterface'); }); }); diff --git a/docs/dgeni-package/templates/type-definition.template.html b/docs/dgeni-package/templates/type-definition.template.html index 002c5ecb8e..aab6d138c4 100644 --- a/docs/dgeni-package/templates/type-definition.template.html +++ b/docs/dgeni-package/templates/type-definition.template.html @@ -1,3 +1,4 @@ + {%- macro commentBlock(doc, level) -%} {%- if doc.content | trim %} @@ -5,6 +6,19 @@ {$ doc.content | trim | replace(r/^/gm, "* ") | indent(level, true) | replace(r/\n$/, "") $} {$ '*/' | indent(level, true) | replace(r/\n$/, "") $}{% endif -%} {%- endmacro -%} + + +{%- macro memberInfo(member) -%} +{$ commentBlock(member, 5) $} + {$ member.name $}{% if member.optional %}?{% endif -%} +{% if member.typeParameters %}<{% for typeParam in member.typeParameters %}{$ typeParam $}{% if not loop.last %}, {% endif %}{% endfor %}>{% endif -%} +{%- if member.parameters -%}({% for param in member.parameters %}{$ param $}{% if not loop.last %}, {% endif %}{% endfor %}){%- endif -%} +{%- if member.returnType -%} + : {$ member.returnType $}{%- else -%}: void +{%- endif -%}; +{%- endmacro -%} + + // Type definitions for Angular v{$ versionInfo.currentVersion.full | replace(r/\+/, "_") $} // Project: http://angular.io/ // Definitions by: angular team @@ -26,25 +40,14 @@ declare module "{$ module.id $}" { {%- endif %} {$ export.docType $} {$ export.name $}{$ export.typeParams $}{$ export.heritage $} {%- if export.docType == 'class' or export.docType == 'interface' %} { - {%- if export.newMember -%} - {$ commentBlock(export.newMember, 5) $} - new ({% for param in export.newMember.parameters %}{$ param $}{% if not loop.last %}, {% endif %}{% endfor %}) - {%- if export.newMember.returnType %}: {$ export.newMember.returnType $}{%- else -%}: any{% endif -%} - ; + {%- if export.newMember %} + {$ memberInfo(export.newMember) $} {% endif %} - {%- if export.callMember -%} - {$ commentBlock(export.callMember, 5) $} - ({% for param in export.callMember.parameters %}{$ param $}{% if not loop.last %}, {% endif %}{% endfor %}) - {%- if export.callMember.returnType %}: {$ export.callMember.returnType $}{%- else -%}: any{% endif -%} - ; - {% endif %} - {%- 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 -%}: void{% endif -%} - ; + {%- if export.callMember %} + {$ memberInfo(export.callMember) $} + {% endif -%} + {%- for member in export.members %} + {$ memberInfo(member) $} {%- endfor %} }