@@ -1764,9 +1764,8 @@ namespace ts {
1764
1764
nameNotFoundMessage: DiagnosticMessage | undefined,
1765
1765
nameArg: __String | Identifier | undefined,
1766
1766
isUse: boolean,
1767
- excludeGlobals = false,
1768
- issueSuggestions?: boolean): Symbol | undefined {
1769
- return resolveNameHelper(location, name, meaning, nameNotFoundMessage, nameArg, isUse, excludeGlobals, getSymbol, issueSuggestions);
1767
+ excludeGlobals = false): Symbol | undefined {
1768
+ return resolveNameHelper(location, name, meaning, nameNotFoundMessage, nameArg, isUse, excludeGlobals, getSymbol);
1770
1769
}
1771
1770
1772
1771
function resolveNameHelper(
@@ -1777,7 +1776,7 @@ namespace ts {
1777
1776
nameArg: __String | Identifier | undefined,
1778
1777
isUse: boolean,
1779
1778
excludeGlobals: boolean,
1780
- lookup: typeof getSymbol, issueSuggestions?: boolean ): Symbol | undefined {
1779
+ lookup: typeof getSymbol): Symbol | undefined {
1781
1780
const originalLocation = location; // needed for did-you-mean error reporting, which gathers candidates starting from the original location
1782
1781
let result: Symbol | undefined;
1783
1782
let lastLocation: Node | undefined;
@@ -2116,7 +2115,7 @@ namespace ts {
2116
2115
!checkAndReportErrorForUsingNamespaceModuleAsValue(errorLocation, name, meaning) &&
2117
2116
!checkAndReportErrorForUsingValueAsType(errorLocation, name, meaning)) {
2118
2117
let suggestion: Symbol | undefined;
2119
- if (issueSuggestions && suggestionCount < maximumSuggestionCount) {
2118
+ if (suggestionCount < maximumSuggestionCount) {
2120
2119
suggestion = getSuggestedSymbolForNonexistentSymbol(originalLocation, name, meaning);
2121
2120
const isGlobalScopeAugmentationDeclaration = suggestion?.valueDeclaration && isAmbientModule(suggestion.valueDeclaration) && isGlobalScopeAugmentation(suggestion.valueDeclaration);
2122
2121
if (isGlobalScopeAugmentationDeclaration) {
@@ -2125,10 +2124,11 @@ namespace ts {
2125
2124
if (suggestion) {
2126
2125
const suggestionName = symbolToString(suggestion);
2127
2126
const isUncheckedJS = isUncheckedJSSuggestion(originalLocation, suggestion, /*excludeClasses*/ false);
2128
- const message = isUncheckedJS ? Diagnostics.Could_not_find_name_0_Did_you_mean_1 : Diagnostics.Cannot_find_name_0_Did_you_mean_1;
2127
+ const message = meaning === SymbolFlags.Namespace || nameArg && typeof nameArg !== "string" && nodeIsSynthesized(nameArg) ? Diagnostics.Cannot_find_namespace_0_Did_you_mean_1
2128
+ : isUncheckedJS ? Diagnostics.Could_not_find_name_0_Did_you_mean_1
2129
+ : Diagnostics.Cannot_find_name_0_Did_you_mean_1;
2129
2130
const diagnostic = createError(errorLocation, message, diagnosticName(nameArg!), suggestionName);
2130
2131
addErrorOrSuggestion(!isUncheckedJS, diagnostic);
2131
-
2132
2132
if (suggestion.valueDeclaration) {
2133
2133
addRelatedInfo(
2134
2134
diagnostic,
@@ -3238,7 +3238,7 @@ namespace ts {
3238
3238
if (name.kind === SyntaxKind.Identifier) {
3239
3239
const message = meaning === namespaceMeaning || nodeIsSynthesized(name) ? Diagnostics.Cannot_find_namespace_0 : getCannotFindNameDiagnosticForName(getFirstIdentifier(name));
3240
3240
const symbolFromJSPrototype = isInJSFile(name) && !nodeIsSynthesized(name) ? resolveEntityNameFromAssignmentDeclaration(name, meaning) : undefined;
3241
- symbol = getMergedSymbol(resolveName(location || name, name.escapedText, meaning, ignoreErrors || symbolFromJSPrototype ? undefined : message, name, /*isUse*/ true));
3241
+ symbol = getMergedSymbol(resolveName(location || name, name.escapedText, meaning, ignoreErrors || symbolFromJSPrototype ? undefined : message, name, /*isUse*/ true, false ));
3242
3242
if (!symbol) {
3243
3243
return getMergedSymbol(symbolFromJSPrototype);
3244
3244
}
@@ -22449,8 +22449,7 @@ namespace ts {
22449
22449
getCannotFindNameDiagnosticForName(node),
22450
22450
node,
22451
22451
!isWriteOnlyAccess(node),
22452
- /*excludeGlobals*/ false,
22453
- /*issueSuggestions*/ true) || unknownSymbol;
22452
+ /*excludeGlobals*/ false) || unknownSymbol;
22454
22453
}
22455
22454
return links.resolvedSymbol;
22456
22455
}
@@ -28535,7 +28534,20 @@ namespace ts {
28535
28534
// Sometimes the symbol is found when location is a return type of a function: `typeof x` and `x` is declared in the body of the function
28536
28535
// So the table *contains* `x` but `x` isn't actually in scope.
28537
28536
// However, resolveNameHelper will continue and call this callback again, so we'll eventually get a correct suggestion.
28538
- return symbol || getSpellingSuggestionForName(unescapeLeadingUnderscores(name), arrayFrom(symbols.values()), meaning);
28537
+ if (symbol) return symbol;
28538
+ let candidates: Symbol[];
28539
+ if (symbols === globals) {
28540
+ const primitives = mapDefined(
28541
+ ["string", "number", "boolean", "object", "bigint", "symbol"],
28542
+ s => symbols.has((s.charAt(0).toUpperCase() + s.slice(1)) as __String)
28543
+ ? createSymbol(SymbolFlags.TypeAlias, s as __String) as Symbol
28544
+ : undefined);
28545
+ candidates = primitives.concat(arrayFrom(symbols.values()));
28546
+ }
28547
+ else {
28548
+ candidates = arrayFrom(symbols.values());
28549
+ }
28550
+ return getSpellingSuggestionForName(unescapeLeadingUnderscores(name), candidates, meaning);
28539
28551
});
28540
28552
return result;
28541
28553
}
0 commit comments