Skip to content

Commit a97ba98

Browse files
authored
infer from usages: support short-circuiting assignment operators (#52860)
1 parent 8369d41 commit a97ba98

File tree

2 files changed

+17
-0
lines changed

2 files changed

+17
-0
lines changed

src/services/codefixes/inferFromUsage.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -869,6 +869,9 @@ function inferTypeFromReferences(program: Program, references: readonly Identifi
869869
case SyntaxKind.EqualsEqualsEqualsToken:
870870
case SyntaxKind.ExclamationEqualsEqualsToken:
871871
case SyntaxKind.ExclamationEqualsToken:
872+
case SyntaxKind.AmpersandAmpersandEqualsToken:
873+
case SyntaxKind.QuestionQuestionEqualsToken:
874+
case SyntaxKind.BarBarEqualsToken:
872875
addCandidateType(usage, checker.getTypeAtLocation(parent.left === node ? parent.right : parent.left));
873876
break;
874877

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
/// <reference path='fourslash.ts' />
2+
3+
// @noImplicitAny: false
4+
////[|let x
5+
////|]
6+
////x ??= 1
7+
////x ||= "2"
8+
////x &&= true
9+
10+
verify.codeFix({
11+
description: "Infer type of 'x' from usage",
12+
index: 0,
13+
newRangeContent: 'let x: string | number | boolean\n',
14+
})

0 commit comments

Comments
 (0)