Always suggest spelling corrections

Even for types. Based on #42126, but without the namespace-specific
error message.
This commit is contained in:
Nathan Shively-Sanders 2021-09-30 11:03:07 -07:00
parent fc1a2aa450
commit a734b84ed0
13 changed files with 47 additions and 36 deletions

View file

@ -1757,9 +1757,8 @@ namespace ts {
nameNotFoundMessage: DiagnosticMessage | undefined,
nameArg: __String | Identifier | undefined,
isUse: boolean,
excludeGlobals = false,
issueSuggestions?: boolean): Symbol | undefined {
return resolveNameHelper(location, name, meaning, nameNotFoundMessage, nameArg, isUse, excludeGlobals, getSymbol, issueSuggestions);
excludeGlobals = false): Symbol | undefined {
return resolveNameHelper(location, name, meaning, nameNotFoundMessage, nameArg, isUse, excludeGlobals, getSymbol);
}
function resolveNameHelper(
@ -1770,8 +1769,7 @@ namespace ts {
nameArg: __String | Identifier | undefined,
isUse: boolean,
excludeGlobals: boolean,
lookup: typeof getSymbol,
issueSuggestions?: boolean): Symbol | undefined {
lookup: typeof getSymbol): Symbol | undefined {
const originalLocation = location; // needed for did-you-mean error reporting, which gathers candidates starting from the original location
let result: Symbol | undefined;
let lastLocation: Node | undefined;
@ -2110,7 +2108,7 @@ namespace ts {
!checkAndReportErrorForUsingNamespaceModuleAsValue(errorLocation, name, meaning) &&
!checkAndReportErrorForUsingValueAsType(errorLocation, name, meaning)) {
let suggestion: Symbol | undefined;
if (issueSuggestions && suggestionCount < maximumSuggestionCount) {
if (suggestionCount < maximumSuggestionCount) {
suggestion = getSuggestedSymbolForNonexistentSymbol(originalLocation, name, meaning);
const isGlobalScopeAugmentationDeclaration = suggestion?.valueDeclaration && isAmbientModule(suggestion.valueDeclaration) && isGlobalScopeAugmentation(suggestion.valueDeclaration);
if (isGlobalScopeAugmentationDeclaration) {
@ -22398,8 +22396,7 @@ namespace ts {
getCannotFindNameDiagnosticForName(node),
node,
!isWriteOnlyAccess(node),
/*excludeGlobals*/ false,
/*issueSuggestions*/ true) || unknownSymbol;
/*excludeGlobals*/ false) || unknownSymbol;
}
return links.resolvedSymbol;
}

View file

@ -1,10 +1,13 @@
tests/cases/compiler/declarationEmitUnknownImport.ts(1,1): error TS2303: Circular definition of import alias 'Foo'.
tests/cases/compiler/declarationEmitUnknownImport.ts(1,14): error TS2304: Cannot find name 'SomeNonExistingName'.
tests/cases/compiler/declarationEmitUnknownImport.ts(1,14): error TS2503: Cannot find namespace 'SomeNonExistingName'.
tests/cases/compiler/declarationEmitUnknownImport.ts(1,14): error TS4000: Import declaration 'Foo' is using private name 'SomeNonExistingName'.
==== tests/cases/compiler/declarationEmitUnknownImport.ts (3 errors) ====
==== tests/cases/compiler/declarationEmitUnknownImport.ts (4 errors) ====
import Foo = SomeNonExistingName
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
!!! error TS2303: Circular definition of import alias 'Foo'.
~~~~~~~~~~~~~~~~~~~
!!! error TS2304: Cannot find name 'SomeNonExistingName'.
~~~~~~~~~~~~~~~~~~~

View file

@ -1,3 +1,4 @@
tests/cases/compiler/declarationEmitUnknownImport2.ts(1,1): error TS2303: Circular definition of import alias 'Foo'.
tests/cases/compiler/declarationEmitUnknownImport2.ts(1,12): error TS1005: '=' expected.
tests/cases/compiler/declarationEmitUnknownImport2.ts(1,12): error TS2304: Cannot find name 'From'.
tests/cases/compiler/declarationEmitUnknownImport2.ts(1,12): error TS2503: Cannot find namespace 'From'.
@ -5,8 +6,10 @@ tests/cases/compiler/declarationEmitUnknownImport2.ts(1,12): error TS4000: Impor
tests/cases/compiler/declarationEmitUnknownImport2.ts(1,17): error TS1005: ';' expected.
==== tests/cases/compiler/declarationEmitUnknownImport2.ts (5 errors) ====
==== tests/cases/compiler/declarationEmitUnknownImport2.ts (6 errors) ====
import Foo From './Foo'; // Syntax error
~~~~~~~~~~~~~~~
!!! error TS2303: Circular definition of import alias 'Foo'.
~~~~
!!! error TS1005: '=' expected.
~~~~

View file

@ -1,5 +1,5 @@
tests/cases/compiler/extendArray.ts(7,19): error TS2304: Cannot find name '_element'.
tests/cases/compiler/extendArray.ts(7,32): error TS2304: Cannot find name '_element'.
tests/cases/compiler/extendArray.ts(7,19): error TS2552: Cannot find name '_element'. Did you mean 'Element'?
tests/cases/compiler/extendArray.ts(7,32): error TS2552: Cannot find name '_element'. Did you mean 'Element'?
==== tests/cases/compiler/extendArray.ts (2 errors) ====
@ -11,9 +11,11 @@ tests/cases/compiler/extendArray.ts(7,32): error TS2304: Cannot find name '_elem
interface Array {
collect(fn:(e:_element) => _element[]) : any[];
~~~~~~~~
!!! error TS2304: Cannot find name '_element'.
!!! error TS2552: Cannot find name '_element'. Did you mean 'Element'?
!!! related TS2728 /.ts/lib.dom.d.ts:4792:13: 'Element' is declared here.
~~~~~~~~
!!! error TS2304: Cannot find name '_element'.
!!! error TS2552: Cannot find name '_element'. Did you mean 'Element'?
!!! related TS2728 /.ts/lib.dom.d.ts:4792:13: 'Element' is declared here.
}
}

View file

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

View file

@ -1,6 +1,6 @@
tests/cases/conformance/internalModules/moduleDeclarations/invalidInstantiatedModule.ts(2,18): error TS2300: Duplicate identifier 'Point'.
tests/cases/conformance/internalModules/moduleDeclarations/invalidInstantiatedModule.ts(3,16): error TS2300: Duplicate identifier 'Point'.
tests/cases/conformance/internalModules/moduleDeclarations/invalidInstantiatedModule.ts(12,8): error TS2503: Cannot find namespace 'm'.
tests/cases/conformance/internalModules/moduleDeclarations/invalidInstantiatedModule.ts(12,8): error TS2552: Cannot find name 'm'. Did you mean 'M'?
==== tests/cases/conformance/internalModules/moduleDeclarations/invalidInstantiatedModule.ts (3 errors) ====
@ -21,7 +21,8 @@ tests/cases/conformance/internalModules/moduleDeclarations/invalidInstantiatedMo
var m = M2;
var p: m.Point; // Error
~
!!! error TS2503: Cannot find namespace 'm'.
!!! error TS2552: Cannot find name 'm'. Did you mean 'M'?
!!! related TS2728 tests/cases/conformance/internalModules/moduleDeclarations/invalidInstantiatedModule.ts:1:8: 'M' is declared here.

View file

@ -1,4 +1,4 @@
/a.js(3,15): error TS2304: Cannot find name 'sting'.
/a.js(3,15): error TS2552: Cannot find name 'sting'. Did you mean 'String'?
==== /a.js (1 errors) ====
@ -6,7 +6,8 @@
* @typedef MyType
* @property {sting} [x]
~~~~~
!!! error TS2304: Cannot find name 'sting'.
!!! error TS2552: Cannot find name 'sting'. Did you mean 'String'?
!!! related TS2728 /.ts/lib.es5.d.ts:530:13: 'String' is declared here.
*/
/** @param {MyType} p */

View file

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

View file

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

View file

@ -1,11 +1,11 @@
tests/cases/conformance/parser/ecmascript5/ErrorRecovery/parserUnfinishedTypeNameBeforeKeyword1.ts(1,8): error TS2503: Cannot find namespace 'TypeModule1'.
tests/cases/conformance/parser/ecmascript5/ErrorRecovery/parserUnfinishedTypeNameBeforeKeyword1.ts(1,8): error TS2552: Cannot find name 'TypeModule1'. Did you mean 'TypeModule2'?
tests/cases/conformance/parser/ecmascript5/ErrorRecovery/parserUnfinishedTypeNameBeforeKeyword1.ts(1,20): error TS1003: Identifier expected.
==== tests/cases/conformance/parser/ecmascript5/ErrorRecovery/parserUnfinishedTypeNameBeforeKeyword1.ts (2 errors) ====
var x: TypeModule1.
~~~~~~~~~~~
!!! error TS2503: Cannot find namespace 'TypeModule1'.
!!! error TS2552: Cannot find name 'TypeModule1'. Did you mean 'TypeModule2'?
!!! error TS1003: Identifier expected.
module TypeModule2 {

View file

@ -1,5 +1,5 @@
tests/cases/conformance/parser/ecmascript5/ErrorRecovery/parserUnterminatedGeneric1.ts(2,23): error TS2304: Cannot find name 'IPromise'.
tests/cases/conformance/parser/ecmascript5/ErrorRecovery/parserUnterminatedGeneric1.ts(2,45): error TS2304: Cannot find name 'IPromise'.
tests/cases/conformance/parser/ecmascript5/ErrorRecovery/parserUnterminatedGeneric1.ts(2,23): error TS2552: Cannot find name 'IPromise'. Did you mean 'Promise'?
tests/cases/conformance/parser/ecmascript5/ErrorRecovery/parserUnterminatedGeneric1.ts(2,45): error TS2552: Cannot find name 'IPromise'. Did you mean 'Promise'?
tests/cases/conformance/parser/ecmascript5/ErrorRecovery/parserUnterminatedGeneric1.ts(2,54): error TS1005: '>' expected.
@ -7,8 +7,8 @@ tests/cases/conformance/parser/ecmascript5/ErrorRecovery/parserUnterminatedGener
interface IQService {
all(promises: IPromise < any > []): IPromise<
~~~~~~~~
!!! error TS2304: Cannot find name 'IPromise'.
!!! error TS2552: Cannot find name 'IPromise'. Did you mean 'Promise'?
~~~~~~~~
!!! error TS2304: Cannot find name 'IPromise'.
!!! error TS2552: Cannot find name 'IPromise'. Did you mean 'Promise'?
!!! error TS1005: '>' expected.

View file

@ -10,8 +10,8 @@ tests/cases/conformance/parser/ecmascript5/ErrorRecovery/parserUnterminatedGener
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.
tests/cases/conformance/parser/ecmascript5/ErrorRecovery/parserUnterminatedGeneric2.ts(4,41): error TS1005: ';' expected.
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.
tests/cases/conformance/parser/ecmascript5/ErrorRecovery/parserUnterminatedGeneric2.ts(8,23): error TS2304: Cannot find name 'IPromise'.
tests/cases/conformance/parser/ecmascript5/ErrorRecovery/parserUnterminatedGeneric2.ts(8,45): error TS2304: Cannot find name 'IPromise'.
tests/cases/conformance/parser/ecmascript5/ErrorRecovery/parserUnterminatedGeneric2.ts(8,23): error TS2552: Cannot find name 'IPromise'. Did you mean 'Promise'?
tests/cases/conformance/parser/ecmascript5/ErrorRecovery/parserUnterminatedGeneric2.ts(8,45): error TS2552: Cannot find name 'IPromise'. Did you mean 'Promise'?
tests/cases/conformance/parser/ecmascript5/ErrorRecovery/parserUnterminatedGeneric2.ts(8,54): error TS1005: '>' expected.
@ -49,8 +49,8 @@ tests/cases/conformance/parser/ecmascript5/ErrorRecovery/parserUnterminatedGener
interface IQService {
all(promises: IPromise < any > []): IPromise<
~~~~~~~~
!!! error TS2304: Cannot find name 'IPromise'.
!!! error TS2552: Cannot find name 'IPromise'. Did you mean 'Promise'?
~~~~~~~~
!!! error TS2304: Cannot find name 'IPromise'.
!!! error TS2552: Cannot find name 'IPromise'. Did you mean 'Promise'?
!!! error TS1005: '>' expected.

View file

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