Merge pull request #27376 from Microsoft/codeFixCannotFindModule_suggestion_falsePositive

Don't implicit-any diagnostic for json module
This commit is contained in:
Sheetal Nandi 2018-11-16 15:48:37 -08:00 committed by GitHub
commit 6bb1ff2214
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 19 additions and 2 deletions

View File

@ -2270,7 +2270,7 @@ namespace ts {
const sourceFile = resolvedModule && !resolutionDiagnostic && host.getSourceFile(resolvedModule.resolvedFileName);
if (sourceFile) {
if (sourceFile.symbol) {
if (resolvedModule.isExternalLibraryImport && !extensionIsTS(resolvedModule.extension)) {
if (resolvedModule.isExternalLibraryImport && !resolutionExtensionIsTSOrJson(resolvedModule.extension)) {
errorOnImplicitAnyModule(/*isError*/ false, errorNode, resolvedModule, moduleReference);
}
// merged symbol is module declaration symbol combined with all augmentations

View File

@ -571,7 +571,8 @@ namespace FourSlash {
public verifyNoErrors() {
ts.forEachKey(this.inputFiles, fileName => {
if (!ts.isAnySupportedFileExtension(fileName)
|| !this.getProgram().getCompilerOptions().allowJs && !ts.extensionIsTS(ts.extensionFromPath(fileName))) return;
|| Harness.getConfigNameFromFileName(fileName)
|| !this.getProgram().getCompilerOptions().allowJs && !ts.resolutionExtensionIsTSOrJson(ts.extensionFromPath(fileName))) return;
const errors = this.getDiagnostics(fileName).filter(e => e.category !== ts.DiagnosticCategory.Suggestion);
if (errors.length) {
this.printErrorLog(/*expectErrors*/ false, errors);

View File

@ -0,0 +1,16 @@
/// <reference path='fourslash.ts' />
// @moduleResolution: node
// @resolveJsonModule: true
// @strict: true
// @Filename: /node_modules/foo/bar.json
////{ "a": 0 }
// @Filename: /a.ts
////import abs = require([|"foo/bar.json"|]);
////abs;
verify.noErrors();
goTo.file("/a.ts");
verify.getSuggestionDiagnostics([]);