mirror of
https://github.com/microsoft/TypeScript.git
synced 2025-11-18 17:21:48 +00:00
Variables from different module declarations default to their declared type
This commit is contained in:
@@ -7936,7 +7936,7 @@ namespace ts {
|
||||
const declaration = localOrExportSymbol.valueDeclaration;
|
||||
const defaultsToDeclaredType = !strictNullChecks || !declaration ||
|
||||
declaration.kind === SyntaxKind.Parameter || isInAmbientContext(declaration) ||
|
||||
getContainingFunctionOrSourceFile(declaration) !== getContainingFunctionOrSourceFile(node);
|
||||
getContainingFunctionOrModule(declaration) !== getContainingFunctionOrModule(node);
|
||||
if (defaultsToDeclaredType && !(type.flags & TypeFlags.Narrowable)) {
|
||||
return type;
|
||||
}
|
||||
|
||||
@@ -840,11 +840,11 @@ namespace ts {
|
||||
}
|
||||
}
|
||||
|
||||
export function getContainingFunctionOrSourceFile(node: Node): FunctionLikeDeclaration | SourceFile {
|
||||
export function getContainingFunctionOrModule(node: Node): Node {
|
||||
while (true) {
|
||||
node = node.parent;
|
||||
if (isFunctionLike(node) || node.kind === SyntaxKind.SourceFile) {
|
||||
return <FunctionLikeDeclaration | SourceFile>node;
|
||||
if (isFunctionLike(node) || node.kind === SyntaxKind.ModuleDeclaration || node.kind === SyntaxKind.SourceFile) {
|
||||
return node;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user