Skip to content

Commit b7484b7

Browse files
authored
Merge pull request #16266 from Microsoft/favour-exact-spelling-suggestion
Always suggest spelling candidate that differs only by case if one exists
2 parents ccc60c8 + 1d8f57e commit b7484b7

File tree

4 files changed

+53
-1
lines changed

4 files changed

+53
-1
lines changed

src/compiler/checker.ts

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14522,6 +14522,7 @@ namespace ts {
1452214522
const maximumLengthDifference = Math.min(3, name.length * 0.34);
1452314523
let bestDistance = Number.MAX_VALUE;
1452414524
let bestCandidate = undefined;
14525+
let justCheckExactMatches = false;
1452514526
if (name.length > 30) {
1452614527
return undefined;
1452714528
}
@@ -14534,6 +14535,9 @@ namespace ts {
1453414535
if (candidateName === name) {
1453514536
return candidate;
1453614537
}
14538+
if (justCheckExactMatches) {
14539+
continue;
14540+
}
1453714541
if (candidateName.length < 3 ||
1453814542
name.length < 3 ||
1453914543
candidateName === "eval" ||
@@ -14549,7 +14553,8 @@ namespace ts {
1454914553
continue;
1455014554
}
1455114555
if (distance < 3) {
14552-
return candidate;
14556+
justCheckExactMatches = true;
14557+
bestCandidate = candidate;
1455314558
}
1455414559
else if (distance < bestDistance) {
1455514560
bestDistance = distance;
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
tests/cases/compiler/exactSpellingSuggestion.ts(9,4): error TS2551: Property 'bit_2' does not exist on type 'typeof U8'. Did you mean 'BIT_2'?
2+
3+
4+
==== tests/cases/compiler/exactSpellingSuggestion.ts (1 errors) ====
5+
// Fixes #16245 -- always suggest the exact match, even when
6+
// other options are very close
7+
enum U8 {
8+
BIT_0 = 1 << 0,
9+
BIT_1 = 1 << 1,
10+
BIT_2 = 1 << 2
11+
}
12+
13+
U8.bit_2
14+
~~~~~
15+
!!! error TS2551: Property 'bit_2' does not exist on type 'typeof U8'. Did you mean 'BIT_2'?
16+
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
//// [exactSpellingSuggestion.ts]
2+
// Fixes #16245 -- always suggest the exact match, even when
3+
// other options are very close
4+
enum U8 {
5+
BIT_0 = 1 << 0,
6+
BIT_1 = 1 << 1,
7+
BIT_2 = 1 << 2
8+
}
9+
10+
U8.bit_2
11+
12+
13+
//// [exactSpellingSuggestion.js]
14+
// Fixes #16245 -- always suggest the exact match, even when
15+
// other options are very close
16+
var U8;
17+
(function (U8) {
18+
U8[U8["BIT_0"] = 1] = "BIT_0";
19+
U8[U8["BIT_1"] = 2] = "BIT_1";
20+
U8[U8["BIT_2"] = 4] = "BIT_2";
21+
})(U8 || (U8 = {}));
22+
U8.bit_2;
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
// Fixes #16245 -- always suggest the exact match, even when
2+
// other options are very close
3+
enum U8 {
4+
BIT_0 = 1 << 0,
5+
BIT_1 = 1 << 1,
6+
BIT_2 = 1 << 2
7+
}
8+
9+
U8.bit_2

0 commit comments

Comments
 (0)