Variables from different source files default to their declared type

This commit is contained in:
Anders Hejlsberg 2016-04-19 10:04:17 -07:00
parent d28a4feeba
commit d735b7acbf
2 changed files with 10 additions and 1 deletions

View file

@ -7936,7 +7936,7 @@ namespace ts {
const declaration = localOrExportSymbol.valueDeclaration;
const defaultsToDeclaredType = !strictNullChecks || !declaration ||
declaration.kind === SyntaxKind.Parameter || isInAmbientContext(declaration) ||
getContainingFunction(declaration) !== getContainingFunction(node);
getContainingFunctionOrSourceFile(declaration) !== getContainingFunctionOrSourceFile(node);
if (defaultsToDeclaredType && !(type.flags & TypeFlags.Narrowable)) {
return type;
}

View file

@ -840,6 +840,15 @@ namespace ts {
}
}
export function getContainingFunctionOrSourceFile(node: Node): FunctionLikeDeclaration | SourceFile {
while (true) {
node = node.parent;
if (isFunctionLike(node) || node.kind === SyntaxKind.SourceFile) {
return <FunctionLikeDeclaration | SourceFile>node;
}
}
}
export function getContainingClass(node: Node): ClassLikeDeclaration {
while (true) {
node = node.parent;