Skip to content

Commit 2fd8687

Browse files
fencimblakeembrey
authored andcommitted
Attempt to use parent getTypeAtLocation (#333)
1 parent 9ebc317 commit 2fd8687

File tree

1 file changed

+13
-9
lines changed

1 file changed

+13
-9
lines changed

src/lib/converter/context.ts

Lines changed: 13 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -138,17 +138,21 @@ export class Context
138138
* @returns The type declaration of the given node.
139139
*/
140140
getTypeAtLocation(node:ts.Node):ts.Type {
141+
var nodeType:ts.Type;
141142
try {
142-
return this.checker.getTypeAtLocation(node);
143-
} catch (error) {
144-
try {
145-
if (node.symbol) {
146-
return this.checker.getDeclaredTypeOfSymbol(node.symbol);
147-
}
148-
} catch (error) {}
143+
nodeType = this.checker.getTypeAtLocation(node);
144+
} catch (error) {
149145
}
150-
151-
return null;
146+
if (!nodeType) {
147+
if (node.symbol) {
148+
nodeType = this.checker.getDeclaredTypeOfSymbol(node.symbol);
149+
} else if (node.parent && node.parent.symbol) {
150+
nodeType = this.checker.getDeclaredTypeOfSymbol(node.parent.symbol);
151+
} else if (node.parent && node.parent.parent && node.parent.parent.symbol) {
152+
nodeType = this.checker.getDeclaredTypeOfSymbol(node.parent.parent.symbol);
153+
}
154+
}
155+
return nodeType;
152156
}
153157

154158

0 commit comments

Comments
 (0)