Skip to content

Commit eb7c305

Browse files
rklfssaciccarello
authored andcommitted
Added support for generic type aliases (#622)
Include type parameter information for generic type aliases
1 parent dad509d commit eb7c305

File tree

3 files changed

+166
-1
lines changed

3 files changed

+166
-1
lines changed

src/lib/converter/nodes/alias.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ export class AliasConverter extends ConverterNodeComponent<ts.TypeAliasDeclarati
2424
convert(context: Context, node: ts.TypeAliasDeclaration): Reflection {
2525
const alias = createDeclaration(context, node, ReflectionKind.TypeAlias);
2626

27-
context.withScope(alias, () => {
27+
context.withScope(alias, node.typeParameters, () => {
2828
alias.type = this.owner.convertType(context, node.type, context.getTypeAtLocation(node.type));
2929
});
3030

src/test/converter/alias/alias.ts

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
/**
2+
* A type that describes a compare function, e.g. for array.sort().
3+
*/
4+
declare type TCompareFunction<T> = (a: T, b: T) => number;
5+
6+
/**
7+
* A type for IDs.
8+
*/
9+
declare type TId = number | string;
Lines changed: 156 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,156 @@
1+
{
2+
"id": 0,
3+
"name": "typedoc",
4+
"kind": 0,
5+
"flags": {},
6+
"children": [
7+
{
8+
"id": 1,
9+
"name": "\"alias\"",
10+
"kind": 1,
11+
"kindString": "External module",
12+
"flags": {
13+
"isExported": true
14+
},
15+
"originalName": "%BASE%/alias/alias.ts",
16+
"children": [
17+
{
18+
"id": 2,
19+
"name": "TCompareFunction",
20+
"kind": 4194304,
21+
"kindString": "Type alias",
22+
"flags": {},
23+
"comment": {
24+
"shortText": "A type that describes a compare function, e.g. for array.sort()."
25+
},
26+
"typeParameter": [
27+
{
28+
"id": 3,
29+
"name": "T",
30+
"kind": 131072,
31+
"kindString": "Type parameter",
32+
"flags": {}
33+
}
34+
],
35+
"sources": [
36+
{
37+
"fileName": "alias.ts",
38+
"line": 4,
39+
"character": 29
40+
}
41+
],
42+
"type": {
43+
"type": "reflection",
44+
"declaration": {
45+
"id": 4,
46+
"name": "__type",
47+
"kind": 65536,
48+
"kindString": "Type literal",
49+
"flags": {},
50+
"signatures": [
51+
{
52+
"id": 5,
53+
"name": "__call",
54+
"kind": 4096,
55+
"kindString": "Call signature",
56+
"flags": {},
57+
"parameters": [
58+
{
59+
"id": 6,
60+
"name": "a",
61+
"kind": 32768,
62+
"kindString": "Parameter",
63+
"flags": {},
64+
"type": {
65+
"type": "typeParameter",
66+
"name": "T"
67+
}
68+
},
69+
{
70+
"id": 7,
71+
"name": "b",
72+
"kind": 32768,
73+
"kindString": "Parameter",
74+
"flags": {},
75+
"type": {
76+
"type": "typeParameter",
77+
"name": "T"
78+
}
79+
}
80+
],
81+
"type": {
82+
"type": "intrinsic",
83+
"name": "number"
84+
}
85+
}
86+
],
87+
"sources": [
88+
{
89+
"fileName": "alias.ts",
90+
"line": 4,
91+
"character": 34
92+
}
93+
]
94+
}
95+
}
96+
},
97+
{
98+
"id": 8,
99+
"name": "TId",
100+
"kind": 4194304,
101+
"kindString": "Type alias",
102+
"flags": {},
103+
"comment": {
104+
"shortText": "A type for IDs."
105+
},
106+
"sources": [
107+
{
108+
"fileName": "alias.ts",
109+
"line": 9,
110+
"character": 16
111+
}
112+
],
113+
"type": {
114+
"type": "union",
115+
"types": [
116+
{
117+
"type": "intrinsic",
118+
"name": "number"
119+
},
120+
{
121+
"type": "intrinsic",
122+
"name": "string"
123+
}
124+
]
125+
}
126+
}
127+
],
128+
"groups": [
129+
{
130+
"title": "Type aliases",
131+
"kind": 4194304,
132+
"children": [
133+
2,
134+
8
135+
]
136+
}
137+
],
138+
"sources": [
139+
{
140+
"fileName": "alias.ts",
141+
"line": 1,
142+
"character": 0
143+
}
144+
]
145+
}
146+
],
147+
"groups": [
148+
{
149+
"title": "External modules",
150+
"kind": 1,
151+
"children": [
152+
1
153+
]
154+
}
155+
]
156+
}

0 commit comments

Comments
 (0)