mirror of
https://github.com/microsoft/TypeScript.git
synced 2026-02-04 21:53:42 -06:00
infer from usages: support short-circuiting assignment operators (#52860)
This commit is contained in:
parent
8369d41efe
commit
a97ba985b2
@ -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;
|
||||
|
||||
|
||||
14
tests/cases/fourslash/codeFixInferFromUsageAllAssignments.ts
Normal file
14
tests/cases/fourslash/codeFixInferFromUsageAllAssignments.ts
Normal 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',
|
||||
})
|
||||
Loading…
x
Reference in New Issue
Block a user