Skip to content

Commit d6ee54e

Browse files
authored
Merge pull request #10202 from asgerf/js/typescript-conditional-types
JS: Enable type extraction inside conditional types again
2 parents 6e7dcfc + 45d64c4 commit d6ee54e

File tree

2 files changed

+11
-12
lines changed

2 files changed

+11
-12
lines changed

javascript/extractor/lib/typescript/src/ast_extractor.ts

Lines changed: 1 addition & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -168,20 +168,9 @@ export function augmentAst(ast: AugmentedSourceFile, code: string, project: Proj
168168
}
169169
}
170170

171-
// Number of conditional type expressions the visitor is currently inside.
172-
// We disable type extraction inside such type expressions, to avoid complications
173-
// with `infer` types.
174-
let insideConditionalTypes = 0;
175-
176171
visitAstNode(ast);
177172
function visitAstNode(node: AugmentedNode) {
178-
if (node.kind === ts.SyntaxKind.ConditionalType) {
179-
++insideConditionalTypes;
180-
}
181173
ts.forEachChild(node, visitAstNode);
182-
if (node.kind === ts.SyntaxKind.ConditionalType) {
183-
--insideConditionalTypes;
184-
}
185174

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

205-
if (typeChecker != null && insideConditionalTypes === 0) {
194+
if (typeChecker != null) {
206195
if (isTypedNode(node)) {
207196
let contextualType = isContextuallyTypedNode(node)
208197
? typeChecker.getContextualType(node)

javascript/ql/test/library-tests/TypeScript/Types/tests.expected

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -861,6 +861,16 @@ getTypeExprType
861861
| tst.ts:325:30:325:34 | Error | Error |
862862
| tst.ts:331:6:331:16 | FirstString | FirstString<T> |
863863
| tst.ts:331:18:331:18 | T | T |
864+
| tst.ts:332:3:332:3 | T | T |
865+
| tst.ts:332:13:332:50 | [infer ... nown[]] | [S, ...unknown[]] |
866+
| tst.ts:332:14:332:35 | infer S ... string | S |
867+
| tst.ts:332:20:332:20 | S | S |
868+
| tst.ts:332:30:332:35 | string | string |
869+
| tst.ts:332:38:332:49 | ...unknown[] | unknown |
870+
| tst.ts:332:41:332:47 | unknown | unknown |
871+
| tst.ts:332:41:332:49 | unknown[] | unknown[] |
872+
| tst.ts:333:9:333:9 | S | S |
873+
| tst.ts:334:9:334:13 | never | never |
864874
| tst.ts:336:6:336:6 | F | "a" \| "b" |
865875
| tst.ts:336:10:336:20 | FirstString | FirstString<T> |
866876
| tst.ts:336:10:336:50 | FirstSt ... olean]> | "a" \| "b" |

0 commit comments

Comments
 (0)