Skip to content

Commit 4204c20

Browse files
Yannblakeembrey
Yann
authored andcommitted
Handle constructor return types (#389)
1 parent 1a26e95 commit 4204c20

File tree

3 files changed

+238
-1
lines changed

3 files changed

+238
-1
lines changed

src/lib/converter/nodes/constructor.ts

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,10 @@ export class ConstructorConverter extends ConverterNodeComponent<ts.ConstructorD
3939
if (!hasBody || !method.signatures) {
4040
const name = 'new ' + parent.name;
4141
const signature = createSignature(context, node, name, ReflectionKind.ConstructorSignature);
42-
signature.type = new ReferenceType(parent.name, ReferenceType.SYMBOL_ID_RESOLVED, parent);
42+
// If no return type defined, use the parent one.
43+
if (!node.type) {
44+
signature.type = new ReferenceType(parent.name, ReferenceType.SYMBOL_ID_RESOLVED, parent);
45+
}
4346
method.signatures = method.signatures || [];
4447
method.signatures.push(signature);
4548
} else {
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
/// <reference path="../lib.core.d.ts" />
2+
3+
interface IConstructor {
4+
5+
// No return type defined. Used the parent one.
6+
new(x:String, y:String);
7+
8+
// A return type is defined and is the same as the parent one.
9+
new(x:String, y:String) : IConstructor;
10+
11+
// A return type is defined and is not the same as the parent one.
12+
new(x:String, y:String) : IInstance;
13+
}
14+
15+
interface IInstance {}
Lines changed: 219 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,219 @@
1+
{
2+
"id": 0,
3+
"name": "typedoc",
4+
"kind": 0,
5+
"flags": {},
6+
"children": [
7+
{
8+
"id": 1,
9+
"name": "\"constructor-type\"",
10+
"kind": 1,
11+
"kindString": "External module",
12+
"flags": {
13+
"isExported": true
14+
},
15+
"originalName": "%BASE%/constructor-type/constructor-type.ts",
16+
"children": [
17+
{
18+
"id": 2,
19+
"name": "IConstructor",
20+
"kind": 256,
21+
"kindString": "Interface",
22+
"flags": {},
23+
"children": [
24+
{
25+
"id": 3,
26+
"name": "constructor",
27+
"kind": 512,
28+
"kindString": "Constructor",
29+
"flags": {},
30+
"signatures": [
31+
{
32+
"id": 4,
33+
"name": "new IConstructor",
34+
"kind": 16384,
35+
"kindString": "Constructor signature",
36+
"flags": {},
37+
"parameters": [
38+
{
39+
"id": 5,
40+
"name": "x",
41+
"kind": 32768,
42+
"kindString": "Parameter",
43+
"flags": {},
44+
"type": {
45+
"type": "reference",
46+
"name": "String"
47+
}
48+
},
49+
{
50+
"id": 6,
51+
"name": "y",
52+
"kind": 32768,
53+
"kindString": "Parameter",
54+
"flags": {},
55+
"type": {
56+
"type": "reference",
57+
"name": "String"
58+
}
59+
}
60+
],
61+
"type": {
62+
"type": "reference",
63+
"name": "IConstructor",
64+
"id": 2
65+
}
66+
},
67+
{
68+
"id": 7,
69+
"name": "new IConstructor",
70+
"kind": 16384,
71+
"kindString": "Constructor signature",
72+
"flags": {},
73+
"parameters": [
74+
{
75+
"id": 8,
76+
"name": "x",
77+
"kind": 32768,
78+
"kindString": "Parameter",
79+
"flags": {},
80+
"type": {
81+
"type": "reference",
82+
"name": "String"
83+
}
84+
},
85+
{
86+
"id": 9,
87+
"name": "y",
88+
"kind": 32768,
89+
"kindString": "Parameter",
90+
"flags": {},
91+
"type": {
92+
"type": "reference",
93+
"name": "String"
94+
}
95+
}
96+
],
97+
"type": {
98+
"type": "reference",
99+
"name": "IConstructor",
100+
"id": 2
101+
}
102+
},
103+
{
104+
"id": 10,
105+
"name": "new IConstructor",
106+
"kind": 16384,
107+
"kindString": "Constructor signature",
108+
"flags": {},
109+
"parameters": [
110+
{
111+
"id": 11,
112+
"name": "x",
113+
"kind": 32768,
114+
"kindString": "Parameter",
115+
"flags": {},
116+
"type": {
117+
"type": "reference",
118+
"name": "String"
119+
}
120+
},
121+
{
122+
"id": 12,
123+
"name": "y",
124+
"kind": 32768,
125+
"kindString": "Parameter",
126+
"flags": {},
127+
"type": {
128+
"type": "reference",
129+
"name": "String"
130+
}
131+
}
132+
],
133+
"type": {
134+
"type": "reference",
135+
"name": "IInstance",
136+
"id": 13
137+
}
138+
}
139+
],
140+
"sources": [
141+
{
142+
"fileName": "constructor-type.ts",
143+
"line": 3,
144+
"character": 24
145+
},
146+
{
147+
"fileName": "constructor-type.ts",
148+
"line": 6,
149+
"character": 28
150+
},
151+
{
152+
"fileName": "constructor-type.ts",
153+
"line": 9,
154+
"character": 43
155+
}
156+
]
157+
}
158+
],
159+
"groups": [
160+
{
161+
"title": "Constructors",
162+
"kind": 512,
163+
"children": [
164+
3
165+
]
166+
}
167+
],
168+
"sources": [
169+
{
170+
"fileName": "constructor-type.ts",
171+
"line": 3,
172+
"character": 22
173+
}
174+
]
175+
},
176+
{
177+
"id": 13,
178+
"name": "IInstance",
179+
"kind": 256,
180+
"kindString": "Interface",
181+
"flags": {},
182+
"sources": [
183+
{
184+
"fileName": "constructor-type.ts",
185+
"line": 15,
186+
"character": 19
187+
}
188+
]
189+
}
190+
],
191+
"groups": [
192+
{
193+
"title": "Interfaces",
194+
"kind": 256,
195+
"children": [
196+
2,
197+
13
198+
]
199+
}
200+
],
201+
"sources": [
202+
{
203+
"fileName": "constructor-type.ts",
204+
"line": 1,
205+
"character": 0
206+
}
207+
]
208+
}
209+
],
210+
"groups": [
211+
{
212+
"title": "External modules",
213+
"kind": 1,
214+
"children": [
215+
1
216+
]
217+
}
218+
]
219+
}

0 commit comments

Comments
 (0)