diff --git a/src/compiler/checker.ts b/src/compiler/checker.ts index 007edacadc9..9719c2de58e 100644 --- a/src/compiler/checker.ts +++ b/src/compiler/checker.ts @@ -573,7 +573,16 @@ namespace ts { declarationNameToString(propertyName), typeof nameArg === "string" ? nameArg : declarationNameToString(nameArg)); return undefined; } - if (result.flags & SymbolFlags.BlockScopedVariable) { + + // Only check for block-scoped variable if we are looking for the name with variable meaning + // For example, + // declare module foo { + // interface bar {} + // } + // let foo/*1*/: foo/*2*/.bar; + // The foo at /*1*/ and /*2*/ will share same symbol with two meaning block-scope variable and namespace module. + // However, only when we try to resolve name in /*1*/ which is used in variable position, we want to check for block- scoped + if (meaning & SymbolFlags.Variable && result.flags & SymbolFlags.BlockScopedVariable) { checkResolvedBlockScopedVariable(result, errorLocation); } } @@ -4256,11 +4265,11 @@ namespace ts { return getInferredType(context, i); } } - return t; + return t; }; mapper.context = context; - return mapper; + return mapper; } function identityMapper(type: Type): Type {