Merge pull request #8429 from Microsoft/declaredTypeAsInitialType

Declared type as initial type in control flow analysis
This commit is contained in:
Anders Hejlsberg
2016-05-02 21:57:56 -07:00
2 changed files with 3 additions and 3 deletions
+1 -1
View File
@@ -7999,7 +7999,7 @@ namespace ts {
const defaultsToDeclaredType = !strictNullChecks || type.flags & TypeFlags.Any || !declaration ||
getRootDeclaration(declaration).kind === SyntaxKind.Parameter || isInAmbientContext(declaration) ||
getContainingFunctionOrModule(declaration) !== getContainingFunctionOrModule(node);
const flowType = getFlowTypeOfReference(node, type, defaultsToDeclaredType ? type : undefinedType);
const flowType = getFlowTypeOfReference(node, type, defaultsToDeclaredType ? type : addNullableKind(type, TypeFlags.Undefined));
if (strictNullChecks && !(type.flags & TypeFlags.Any) && !(getNullableKind(type) & TypeFlags.Undefined) && getNullableKind(flowType) & TypeFlags.Undefined) {
error(node, Diagnostics.Variable_0_is_used_before_being_assigned, symbolToString(symbol));
// Return the declared type to reduce follow-on errors
@@ -31,8 +31,8 @@ verify.quickInfoIs('(parameter) strOrNum: string');
verify.completionListContains("strOrNum", "(parameter) strOrNum: string");
goTo.marker('4');
verify.quickInfoIs('let s: undefined');
verify.completionListContains("s", "let s: undefined");
verify.quickInfoIs('let s: string | undefined');
verify.completionListContains("s", "let s: string | undefined");
goTo.marker('5');
verify.quickInfoIs('let s: string | undefined');