Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 1 addition & 12 deletions javascript/extractor/lib/typescript/src/ast_extractor.ts
Original file line number Diff line number Diff line change
Expand Up @@ -168,20 +168,9 @@ export function augmentAst(ast: AugmentedSourceFile, code: string, project: Proj
}
}

// Number of conditional type expressions the visitor is currently inside.
// We disable type extraction inside such type expressions, to avoid complications
// with `infer` types.
let insideConditionalTypes = 0;

visitAstNode(ast);
function visitAstNode(node: AugmentedNode) {
if (node.kind === ts.SyntaxKind.ConditionalType) {
++insideConditionalTypes;
}
ts.forEachChild(node, visitAstNode);
if (node.kind === ts.SyntaxKind.ConditionalType) {
--insideConditionalTypes;
}

// fill in line/column info
if ("pos" in node) {
Expand All @@ -202,7 +191,7 @@ export function augmentAst(ast: AugmentedSourceFile, code: string, project: Proj
}
}

if (typeChecker != null && insideConditionalTypes === 0) {
if (typeChecker != null) {
if (isTypedNode(node)) {
let contextualType = isContextuallyTypedNode(node)
? typeChecker.getContextualType(node)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -861,6 +861,16 @@ getTypeExprType
| tst.ts:325:30:325:34 | Error | Error |
| tst.ts:331:6:331:16 | FirstString | FirstString<T> |
| tst.ts:331:18:331:18 | T | T |
| tst.ts:332:3:332:3 | T | T |
| tst.ts:332:13:332:50 | [infer ... nown[]] | [S, ...unknown[]] |
| tst.ts:332:14:332:35 | infer S ... string | S |
| tst.ts:332:20:332:20 | S | S |
| tst.ts:332:30:332:35 | string | string |
| tst.ts:332:38:332:49 | ...unknown[] | unknown |
| tst.ts:332:41:332:47 | unknown | unknown |
| tst.ts:332:41:332:49 | unknown[] | unknown[] |
| tst.ts:333:9:333:9 | S | S |
| tst.ts:334:9:334:13 | never | never |
| tst.ts:336:6:336:6 | F | "a" \| "b" |
| tst.ts:336:10:336:20 | FirstString | FirstString<T> |
| tst.ts:336:10:336:50 | FirstSt ... olean]> | "a" \| "b" |
Expand Down