infer from usages: support short-circuiting assignment operators (#52860)

This commit is contained in:
Vitaly 2023-04-10 23:13:46 +03:00 committed by GitHub
parent 8369d41efe
commit a97ba985b2
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 17 additions and 0 deletions

View File

@ -869,6 +869,9 @@ function inferTypeFromReferences(program: Program, references: readonly Identifi
case SyntaxKind.EqualsEqualsEqualsToken:
case SyntaxKind.ExclamationEqualsEqualsToken:
case SyntaxKind.ExclamationEqualsToken:
case SyntaxKind.AmpersandAmpersandEqualsToken:
case SyntaxKind.QuestionQuestionEqualsToken:
case SyntaxKind.BarBarEqualsToken:
addCandidateType(usage, checker.getTypeAtLocation(parent.left === node ? parent.right : parent.left));
break;

View File

@ -0,0 +1,14 @@
/// <reference path='fourslash.ts' />
// @noImplicitAny: false
////[|let x
////|]
////x ??= 1
////x ||= "2"
////x &&= true
verify.codeFix({
description: "Infer type of 'x' from usage",
index: 0,
newRangeContent: 'let x: string | number | boolean\n',
})