diff --git a/src/compiler/checker.ts b/src/compiler/checker.ts index f42ca9ffe34..0bedc9f404a 100644 --- a/src/compiler/checker.ts +++ b/src/compiler/checker.ts @@ -51,7 +51,7 @@ namespace ts { const compilerOptions = host.getCompilerOptions(); const languageVersion = compilerOptions.target || ScriptTarget.ES3; const modulekind = getEmitModuleKind(compilerOptions); - const noUnusedIdentifiers = compilerOptions.noUnusedLocals || compilerOptions.noUnusedParameters; + const noUnusedIdentifiers = !!compilerOptions.noUnusedLocals || !!compilerOptions.noUnusedParameters; const allowSyntheticDefaultImports = typeof compilerOptions.allowSyntheticDefaultImports !== "undefined" ? compilerOptions.allowSyntheticDefaultImports : modulekind === ModuleKind.System; const strictNullChecks = compilerOptions.strictNullChecks; @@ -849,6 +849,10 @@ namespace ts { location = location.parent; } + if (result && nameNotFoundMessage && noUnusedIdentifiers) { + result.isReferenced = true; + } + if (!result) { result = getSymbol(globals, name, meaning); } @@ -899,10 +903,6 @@ namespace ts { error(errorLocation, Diagnostics.Identifier_0_must_be_imported_from_a_module, name); } } - - if (result && noUnusedIdentifiers && !isInAmbientContext(location)) { - result.isReferenced = true; - } } return result; }