Skip to content

Commit a734b84

Browse files
committed
Always suggest spelling corrections
Even for types. Based on #42126, but without the namespace-specific error message.
1 parent fc1a2aa commit a734b84

13 files changed

+47
-36
lines changed

src/compiler/checker.ts

Lines changed: 5 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1757,9 +1757,8 @@ namespace ts {
17571757
nameNotFoundMessage: DiagnosticMessage | undefined,
17581758
nameArg: __String | Identifier | undefined,
17591759
isUse: boolean,
1760-
excludeGlobals = false,
1761-
issueSuggestions?: boolean): Symbol | undefined {
1762-
return resolveNameHelper(location, name, meaning, nameNotFoundMessage, nameArg, isUse, excludeGlobals, getSymbol, issueSuggestions);
1760+
excludeGlobals = false): Symbol | undefined {
1761+
return resolveNameHelper(location, name, meaning, nameNotFoundMessage, nameArg, isUse, excludeGlobals, getSymbol);
17631762
}
17641763

17651764
function resolveNameHelper(
@@ -1770,8 +1769,7 @@ namespace ts {
17701769
nameArg: __String | Identifier | undefined,
17711770
isUse: boolean,
17721771
excludeGlobals: boolean,
1773-
lookup: typeof getSymbol,
1774-
issueSuggestions?: boolean): Symbol | undefined {
1772+
lookup: typeof getSymbol): Symbol | undefined {
17751773
const originalLocation = location; // needed for did-you-mean error reporting, which gathers candidates starting from the original location
17761774
let result: Symbol | undefined;
17771775
let lastLocation: Node | undefined;
@@ -2110,7 +2108,7 @@ namespace ts {
21102108
!checkAndReportErrorForUsingNamespaceModuleAsValue(errorLocation, name, meaning) &&
21112109
!checkAndReportErrorForUsingValueAsType(errorLocation, name, meaning)) {
21122110
let suggestion: Symbol | undefined;
2113-
if (issueSuggestions && suggestionCount < maximumSuggestionCount) {
2111+
if (suggestionCount < maximumSuggestionCount) {
21142112
suggestion = getSuggestedSymbolForNonexistentSymbol(originalLocation, name, meaning);
21152113
const isGlobalScopeAugmentationDeclaration = suggestion?.valueDeclaration && isAmbientModule(suggestion.valueDeclaration) && isGlobalScopeAugmentation(suggestion.valueDeclaration);
21162114
if (isGlobalScopeAugmentationDeclaration) {
@@ -22398,8 +22396,7 @@ namespace ts {
2239822396
getCannotFindNameDiagnosticForName(node),
2239922397
node,
2240022398
!isWriteOnlyAccess(node),
22401-
/*excludeGlobals*/ false,
22402-
/*issueSuggestions*/ true) || unknownSymbol;
22399+
/*excludeGlobals*/ false) || unknownSymbol;
2240322400
}
2240422401
return links.resolvedSymbol;
2240522402
}

tests/baselines/reference/declarationEmitUnknownImport.errors.txt

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,13 @@
1+
tests/cases/compiler/declarationEmitUnknownImport.ts(1,1): error TS2303: Circular definition of import alias 'Foo'.
12
tests/cases/compiler/declarationEmitUnknownImport.ts(1,14): error TS2304: Cannot find name 'SomeNonExistingName'.
23
tests/cases/compiler/declarationEmitUnknownImport.ts(1,14): error TS2503: Cannot find namespace 'SomeNonExistingName'.
34
tests/cases/compiler/declarationEmitUnknownImport.ts(1,14): error TS4000: Import declaration 'Foo' is using private name 'SomeNonExistingName'.
45

56

6-
==== tests/cases/compiler/declarationEmitUnknownImport.ts (3 errors) ====
7+
==== tests/cases/compiler/declarationEmitUnknownImport.ts (4 errors) ====
78
import Foo = SomeNonExistingName
9+
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
10+
!!! error TS2303: Circular definition of import alias 'Foo'.
811
~~~~~~~~~~~~~~~~~~~
912
!!! error TS2304: Cannot find name 'SomeNonExistingName'.
1013
~~~~~~~~~~~~~~~~~~~

tests/baselines/reference/declarationEmitUnknownImport2.errors.txt

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,15 @@
1+
tests/cases/compiler/declarationEmitUnknownImport2.ts(1,1): error TS2303: Circular definition of import alias 'Foo'.
12
tests/cases/compiler/declarationEmitUnknownImport2.ts(1,12): error TS1005: '=' expected.
23
tests/cases/compiler/declarationEmitUnknownImport2.ts(1,12): error TS2304: Cannot find name 'From'.
34
tests/cases/compiler/declarationEmitUnknownImport2.ts(1,12): error TS2503: Cannot find namespace 'From'.
45
tests/cases/compiler/declarationEmitUnknownImport2.ts(1,12): error TS4000: Import declaration 'Foo' is using private name 'From'.
56
tests/cases/compiler/declarationEmitUnknownImport2.ts(1,17): error TS1005: ';' expected.
67

78

8-
==== tests/cases/compiler/declarationEmitUnknownImport2.ts (5 errors) ====
9+
==== tests/cases/compiler/declarationEmitUnknownImport2.ts (6 errors) ====
910
import Foo From './Foo'; // Syntax error
11+
~~~~~~~~~~~~~~~
12+
!!! error TS2303: Circular definition of import alias 'Foo'.
1013
~~~~
1114
!!! error TS1005: '=' expected.
1215
~~~~

tests/baselines/reference/extendArray.errors.txt

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
1-
tests/cases/compiler/extendArray.ts(7,19): error TS2304: Cannot find name '_element'.
2-
tests/cases/compiler/extendArray.ts(7,32): error TS2304: Cannot find name '_element'.
1+
tests/cases/compiler/extendArray.ts(7,19): error TS2552: Cannot find name '_element'. Did you mean 'Element'?
2+
tests/cases/compiler/extendArray.ts(7,32): error TS2552: Cannot find name '_element'. Did you mean 'Element'?
33

44

55
==== tests/cases/compiler/extendArray.ts (2 errors) ====
@@ -11,9 +11,11 @@ tests/cases/compiler/extendArray.ts(7,32): error TS2304: Cannot find name '_elem
1111
interface Array {
1212
collect(fn:(e:_element) => _element[]) : any[];
1313
~~~~~~~~
14-
!!! error TS2304: Cannot find name '_element'.
14+
!!! error TS2552: Cannot find name '_element'. Did you mean 'Element'?
15+
!!! related TS2728 /.ts/lib.dom.d.ts:4792:13: 'Element' is declared here.
1516
~~~~~~~~
16-
!!! error TS2304: Cannot find name '_element'.
17+
!!! error TS2552: Cannot find name '_element'. Did you mean 'Element'?
18+
!!! related TS2728 /.ts/lib.dom.d.ts:4792:13: 'Element' is declared here.
1719
}
1820
}
1921

tests/baselines/reference/importedModuleAddToGlobal.errors.txt

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
tests/cases/compiler/importedModuleAddToGlobal.ts(15,23): error TS2503: Cannot find namespace 'b'.
1+
tests/cases/compiler/importedModuleAddToGlobal.ts(15,23): error TS2552: Cannot find name 'b'. Did you mean 'B'?
22

33

44
==== tests/cases/compiler/importedModuleAddToGlobal.ts (1 errors) ====
@@ -18,5 +18,6 @@ tests/cases/compiler/importedModuleAddToGlobal.ts(15,23): error TS2503: Cannot f
1818
import a = A;
1919
function hello(): b.B { return null; }
2020
~
21-
!!! error TS2503: Cannot find namespace 'b'.
21+
!!! error TS2552: Cannot find name 'b'. Did you mean 'B'?
22+
!!! related TS2728 tests/cases/compiler/importedModuleAddToGlobal.ts:8:8: 'B' is declared here.
2223
}

tests/baselines/reference/invalidInstantiatedModule.errors.txt

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
tests/cases/conformance/internalModules/moduleDeclarations/invalidInstantiatedModule.ts(2,18): error TS2300: Duplicate identifier 'Point'.
22
tests/cases/conformance/internalModules/moduleDeclarations/invalidInstantiatedModule.ts(3,16): error TS2300: Duplicate identifier 'Point'.
3-
tests/cases/conformance/internalModules/moduleDeclarations/invalidInstantiatedModule.ts(12,8): error TS2503: Cannot find namespace 'm'.
3+
tests/cases/conformance/internalModules/moduleDeclarations/invalidInstantiatedModule.ts(12,8): error TS2552: Cannot find name 'm'. Did you mean 'M'?
44

55

66
==== tests/cases/conformance/internalModules/moduleDeclarations/invalidInstantiatedModule.ts (3 errors) ====
@@ -21,7 +21,8 @@ tests/cases/conformance/internalModules/moduleDeclarations/invalidInstantiatedMo
2121
var m = M2;
2222
var p: m.Point; // Error
2323
~
24-
!!! error TS2503: Cannot find namespace 'm'.
24+
!!! error TS2552: Cannot find name 'm'. Did you mean 'M'?
25+
!!! related TS2728 tests/cases/conformance/internalModules/moduleDeclarations/invalidInstantiatedModule.ts:1:8: 'M' is declared here.
2526

2627

2728

tests/baselines/reference/jsdocPropertyTagInvalid.errors.txt

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,13 @@
1-
/a.js(3,15): error TS2304: Cannot find name 'sting'.
1+
/a.js(3,15): error TS2552: Cannot find name 'sting'. Did you mean 'String'?
22

33

44
==== /a.js (1 errors) ====
55
/**
66
* @typedef MyType
77
* @property {sting} [x]
88
~~~~~
9-
!!! error TS2304: Cannot find name 'sting'.
9+
!!! error TS2552: Cannot find name 'sting'. Did you mean 'String'?
10+
!!! related TS2728 /.ts/lib.es5.d.ts:530:13: 'String' is declared here.
1011
*/
1112

1213
/** @param {MyType} p */

tests/baselines/reference/jsxFactoryIdentifierWithAbsentParameter.errors.txt

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
tests/cases/compiler/test.tsx(9,17): error TS2304: Cannot find name 'createElement'.
1+
tests/cases/compiler/test.tsx(9,17): error TS2552: Cannot find name 'createElement'. Did you mean 'frameElement'?
22

33

44
==== tests/cases/compiler/test.tsx (1 errors) ====
@@ -12,7 +12,8 @@ tests/cases/compiler/test.tsx(9,17): error TS2304: Cannot find name 'createEleme
1212
render() {
1313
return <div />;
1414
~~~
15-
!!! error TS2304: Cannot find name 'createElement'.
15+
!!! error TS2552: Cannot find name 'createElement'. Did you mean 'frameElement'?
16+
!!! related TS2728 /.ts/lib.dom.d.ts:17075:13: 'frameElement' is declared here.
1617
}
1718
}
1819

tests/baselines/reference/jsxFactoryQualifiedNameResolutionError.errors.txt

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
tests/cases/compiler/test.tsx(9,17): error TS2304: Cannot find name 'MyElement'.
1+
tests/cases/compiler/test.tsx(9,17): error TS2552: Cannot find name 'MyElement'. Did you mean 'Element'?
22

33

44
==== tests/cases/compiler/test.tsx (1 errors) ====
@@ -12,6 +12,7 @@ tests/cases/compiler/test.tsx(9,17): error TS2304: Cannot find name 'MyElement'.
1212
render(createElement) {
1313
return <div />;
1414
~~~
15-
!!! error TS2304: Cannot find name 'MyElement'.
15+
!!! error TS2552: Cannot find name 'MyElement'. Did you mean 'Element'?
16+
!!! related TS2728 /.ts/lib.dom.d.ts:4792:13: 'Element' is declared here.
1617
}
1718
}

tests/baselines/reference/parserUnfinishedTypeNameBeforeKeyword1.errors.txt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
1-
tests/cases/conformance/parser/ecmascript5/ErrorRecovery/parserUnfinishedTypeNameBeforeKeyword1.ts(1,8): error TS2503: Cannot find namespace 'TypeModule1'.
1+
tests/cases/conformance/parser/ecmascript5/ErrorRecovery/parserUnfinishedTypeNameBeforeKeyword1.ts(1,8): error TS2552: Cannot find name 'TypeModule1'. Did you mean 'TypeModule2'?
22
tests/cases/conformance/parser/ecmascript5/ErrorRecovery/parserUnfinishedTypeNameBeforeKeyword1.ts(1,20): error TS1003: Identifier expected.
33

44

55
==== tests/cases/conformance/parser/ecmascript5/ErrorRecovery/parserUnfinishedTypeNameBeforeKeyword1.ts (2 errors) ====
66
var x: TypeModule1.
77
~~~~~~~~~~~
8-
!!! error TS2503: Cannot find namespace 'TypeModule1'.
8+
!!! error TS2552: Cannot find name 'TypeModule1'. Did you mean 'TypeModule2'?
99

1010
!!! error TS1003: Identifier expected.
1111
module TypeModule2 {
Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,14 @@
1-
tests/cases/conformance/parser/ecmascript5/ErrorRecovery/parserUnterminatedGeneric1.ts(2,23): error TS2304: Cannot find name 'IPromise'.
2-
tests/cases/conformance/parser/ecmascript5/ErrorRecovery/parserUnterminatedGeneric1.ts(2,45): error TS2304: Cannot find name 'IPromise'.
1+
tests/cases/conformance/parser/ecmascript5/ErrorRecovery/parserUnterminatedGeneric1.ts(2,23): error TS2552: Cannot find name 'IPromise'. Did you mean 'Promise'?
2+
tests/cases/conformance/parser/ecmascript5/ErrorRecovery/parserUnterminatedGeneric1.ts(2,45): error TS2552: Cannot find name 'IPromise'. Did you mean 'Promise'?
33
tests/cases/conformance/parser/ecmascript5/ErrorRecovery/parserUnterminatedGeneric1.ts(2,54): error TS1005: '>' expected.
44

55

66
==== tests/cases/conformance/parser/ecmascript5/ErrorRecovery/parserUnterminatedGeneric1.ts (3 errors) ====
77
interface IQService {
88
all(promises: IPromise < any > []): IPromise<
99
~~~~~~~~
10-
!!! error TS2304: Cannot find name 'IPromise'.
10+
!!! error TS2552: Cannot find name 'IPromise'. Did you mean 'Promise'?
1111
~~~~~~~~
12-
!!! error TS2304: Cannot find name 'IPromise'.
12+
!!! error TS2552: Cannot find name 'IPromise'. Did you mean 'Promise'?
1313

1414
!!! error TS1005: '>' expected.

tests/baselines/reference/parserUnterminatedGeneric2.errors.txt

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,8 @@ tests/cases/conformance/parser/ecmascript5/ErrorRecovery/parserUnterminatedGener
1010
tests/cases/conformance/parser/ecmascript5/ErrorRecovery/parserUnterminatedGeneric2.ts(4,37): error TS2693: 'any' only refers to a type, but is being used as a value here.
1111
tests/cases/conformance/parser/ecmascript5/ErrorRecovery/parserUnterminatedGeneric2.ts(4,41): error TS1005: ';' expected.
1212
tests/cases/conformance/parser/ecmascript5/ErrorRecovery/parserUnterminatedGeneric2.ts(4,43): error TS2693: 'any' only refers to a type, but is being used as a value here.
13-
tests/cases/conformance/parser/ecmascript5/ErrorRecovery/parserUnterminatedGeneric2.ts(8,23): error TS2304: Cannot find name 'IPromise'.
14-
tests/cases/conformance/parser/ecmascript5/ErrorRecovery/parserUnterminatedGeneric2.ts(8,45): error TS2304: Cannot find name 'IPromise'.
13+
tests/cases/conformance/parser/ecmascript5/ErrorRecovery/parserUnterminatedGeneric2.ts(8,23): error TS2552: Cannot find name 'IPromise'. Did you mean 'Promise'?
14+
tests/cases/conformance/parser/ecmascript5/ErrorRecovery/parserUnterminatedGeneric2.ts(8,45): error TS2552: Cannot find name 'IPromise'. Did you mean 'Promise'?
1515
tests/cases/conformance/parser/ecmascript5/ErrorRecovery/parserUnterminatedGeneric2.ts(8,54): error TS1005: '>' expected.
1616

1717

@@ -49,8 +49,8 @@ tests/cases/conformance/parser/ecmascript5/ErrorRecovery/parserUnterminatedGener
4949
interface IQService {
5050
all(promises: IPromise < any > []): IPromise<
5151
~~~~~~~~
52-
!!! error TS2304: Cannot find name 'IPromise'.
52+
!!! error TS2552: Cannot find name 'IPromise'. Did you mean 'Promise'?
5353
~~~~~~~~
54-
!!! error TS2304: Cannot find name 'IPromise'.
54+
!!! error TS2552: Cannot find name 'IPromise'. Did you mean 'Promise'?
5555

5656
!!! error TS1005: '>' expected.

tests/baselines/reference/primaryExpressionMods.errors.txt

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
tests/cases/compiler/primaryExpressionMods.ts(7,8): error TS2709: Cannot use namespace 'M' as a type.
2-
tests/cases/compiler/primaryExpressionMods.ts(11,8): error TS2503: Cannot find namespace 'm'.
2+
tests/cases/compiler/primaryExpressionMods.ts(11,8): error TS2552: Cannot find name 'm'. Did you mean 'M'?
33

44

55
==== tests/cases/compiler/primaryExpressionMods.ts (2 errors) ====
@@ -17,5 +17,6 @@ tests/cases/compiler/primaryExpressionMods.ts(11,8): error TS2503: Cannot find n
1717
var x2 = m.a; // Same as M.a
1818
var q: m.P; // Error
1919
~
20-
!!! error TS2503: Cannot find namespace 'm'.
20+
!!! error TS2552: Cannot find name 'm'. Did you mean 'M'?
21+
!!! related TS2728 tests/cases/compiler/primaryExpressionMods.ts:1:8: 'M' is declared here.
2122

0 commit comments

Comments
 (0)