diff --git a/src/compiler/checker.ts b/src/compiler/checker.ts index 7105e3605aa..ab0d9b385f4 100644 --- a/src/compiler/checker.ts +++ b/src/compiler/checker.ts @@ -585,7 +585,7 @@ namespace ts { checkSourceFile(file); Debug.assert(!!(getNodeLinks(file).flags & NodeCheckFlags.TypeChecked)); - diagnostics = addRange(diagnostics, suggestionDiagnostics.get(file.fileName)); + diagnostics = addRange(diagnostics, suggestionDiagnostics.getDiagnostics(file.fileName)); if (!file.isDeclarationFile && (!unusedIsError(UnusedKind.Local) || !unusedIsError(UnusedKind.Parameter))) { addUnusedDiagnostics(); } @@ -848,8 +848,7 @@ namespace ts { const awaitedTypeStack: number[] = []; const diagnostics = createDiagnosticCollection(); - // Suggestion diagnostics must have a file. Keyed by source file name. - const suggestionDiagnostics = createMultiMap(); + const suggestionDiagnostics = createDiagnosticCollection(); const typeofTypesByName: ReadonlyMap = createMapFromTemplate({ string: stringType, @@ -944,7 +943,7 @@ namespace ts { diagnostics.add(diagnostic); } else { - suggestionDiagnostics.add(diagnostic.file.fileName, { ...diagnostic, category: DiagnosticCategory.Suggestion }); + suggestionDiagnostics.add({ ...diagnostic, category: DiagnosticCategory.Suggestion }); } } function errorOrSuggestion(isError: boolean, location: Node, message: DiagnosticMessage | DiagnosticMessageChain, arg0?: string | number, arg1?: string | number, arg2?: string | number, arg3?: string | number): void { diff --git a/tests/cases/fourslash/suggestionNoDuplicates.ts b/tests/cases/fourslash/suggestionNoDuplicates.ts new file mode 100644 index 00000000000..fa5eadf1e0b --- /dev/null +++ b/tests/cases/fourslash/suggestionNoDuplicates.ts @@ -0,0 +1,14 @@ +// @strict: false +/// +// @Filename: foo.ts +//// import { f } from [|'m'|] +//// f + +// @Filename: node_modules/m/index.js +//// module.exports.f = function (x) { return x } + +verify.getSemanticDiagnostics([]) +verify.getSuggestionDiagnostics([{ + code: 7016, + message: "Could not find a declaration file for module 'm'. '/tests/cases/fourslash/node_modules/m/index.js' implicitly has an 'any' type.", +}])