Skip to content

Commit

Permalink
Added support for generic type aliases (#622)
Browse files Browse the repository at this point in the history
Include type parameter information for generic type aliases
  • Loading branch information
rklfss authored and aciccarello committed Dec 16, 2017
1 parent dad509d commit eb7c305
Show file tree
Hide file tree
Showing 3 changed files with 166 additions and 1 deletion.
2 changes: 1 addition & 1 deletion src/lib/converter/nodes/alias.ts
Expand Up @@ -24,7 +24,7 @@ export class AliasConverter extends ConverterNodeComponent<ts.TypeAliasDeclarati
convert(context: Context, node: ts.TypeAliasDeclaration): Reflection {
const alias = createDeclaration(context, node, ReflectionKind.TypeAlias);

context.withScope(alias, () => {
context.withScope(alias, node.typeParameters, () => {
alias.type = this.owner.convertType(context, node.type, context.getTypeAtLocation(node.type));
});

Expand Down
9 changes: 9 additions & 0 deletions src/test/converter/alias/alias.ts
@@ -0,0 +1,9 @@
/**
* A type that describes a compare function, e.g. for array.sort().
*/
declare type TCompareFunction<T> = (a: T, b: T) => number;

/**
* A type for IDs.
*/
declare type TId = number | string;
156 changes: 156 additions & 0 deletions src/test/converter/alias/specs.json
@@ -0,0 +1,156 @@
{
"id": 0,
"name": "typedoc",
"kind": 0,
"flags": {},
"children": [
{
"id": 1,
"name": "\"alias\"",
"kind": 1,
"kindString": "External module",
"flags": {
"isExported": true
},
"originalName": "%BASE%/alias/alias.ts",
"children": [
{
"id": 2,
"name": "TCompareFunction",
"kind": 4194304,
"kindString": "Type alias",
"flags": {},
"comment": {
"shortText": "A type that describes a compare function, e.g. for array.sort()."
},
"typeParameter": [
{
"id": 3,
"name": "T",
"kind": 131072,
"kindString": "Type parameter",
"flags": {}
}
],
"sources": [
{
"fileName": "alias.ts",
"line": 4,
"character": 29
}
],
"type": {
"type": "reflection",
"declaration": {
"id": 4,
"name": "__type",
"kind": 65536,
"kindString": "Type literal",
"flags": {},
"signatures": [
{
"id": 5,
"name": "__call",
"kind": 4096,
"kindString": "Call signature",
"flags": {},
"parameters": [
{
"id": 6,
"name": "a",
"kind": 32768,
"kindString": "Parameter",
"flags": {},
"type": {
"type": "typeParameter",
"name": "T"
}
},
{
"id": 7,
"name": "b",
"kind": 32768,
"kindString": "Parameter",
"flags": {},
"type": {
"type": "typeParameter",
"name": "T"
}
}
],
"type": {
"type": "intrinsic",
"name": "number"
}
}
],
"sources": [
{
"fileName": "alias.ts",
"line": 4,
"character": 34
}
]
}
}
},
{
"id": 8,
"name": "TId",
"kind": 4194304,
"kindString": "Type alias",
"flags": {},
"comment": {
"shortText": "A type for IDs."
},
"sources": [
{
"fileName": "alias.ts",
"line": 9,
"character": 16
}
],
"type": {
"type": "union",
"types": [
{
"type": "intrinsic",
"name": "number"
},
{
"type": "intrinsic",
"name": "string"
}
]
}
}
],
"groups": [
{
"title": "Type aliases",
"kind": 4194304,
"children": [
2,
8
]
}
],
"sources": [
{
"fileName": "alias.ts",
"line": 1,
"character": 0
}
]
}
],
"groups": [
{
"title": "External modules",
"kind": 1,
"children": [
1
]
}
]
}

0 comments on commit eb7c305

Please sign in to comment.