Skip to content

Commit 2ff9c91

Browse files
committed
Merge pull request #8429 from Microsoft/declaredTypeAsInitialType
Declared type as initial type in control flow analysis
2 parents 8173ee9 + dbfe80b commit 2ff9c91

File tree

2 files changed

+3
-3
lines changed

2 files changed

+3
-3
lines changed

src/compiler/checker.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7999,7 +7999,7 @@ namespace ts {
79997999
const defaultsToDeclaredType = !strictNullChecks || type.flags & TypeFlags.Any || !declaration ||
80008000
getRootDeclaration(declaration).kind === SyntaxKind.Parameter || isInAmbientContext(declaration) ||
80018001
getContainingFunctionOrModule(declaration) !== getContainingFunctionOrModule(node);
8002-
const flowType = getFlowTypeOfReference(node, type, defaultsToDeclaredType ? type : undefinedType);
8002+
const flowType = getFlowTypeOfReference(node, type, defaultsToDeclaredType ? type : addNullableKind(type, TypeFlags.Undefined));
80038003
if (strictNullChecks && !(type.flags & TypeFlags.Any) && !(getNullableKind(type) & TypeFlags.Undefined) && getNullableKind(flowType) & TypeFlags.Undefined) {
80048004
error(node, Diagnostics.Variable_0_is_used_before_being_assigned, symbolToString(symbol));
80058005
// Return the declared type to reduce follow-on errors

tests/cases/fourslash/quickInfoOnNarrowedType.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -31,8 +31,8 @@ verify.quickInfoIs('(parameter) strOrNum: string');
3131
verify.completionListContains("strOrNum", "(parameter) strOrNum: string");
3232

3333
goTo.marker('4');
34-
verify.quickInfoIs('let s: undefined');
35-
verify.completionListContains("s", "let s: undefined");
34+
verify.quickInfoIs('let s: string | undefined');
35+
verify.completionListContains("s", "let s: string | undefined");
3636

3737
goTo.marker('5');
3838
verify.quickInfoIs('let s: string | undefined');

0 commit comments

Comments
 (0)