Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Remove getNonNullableType application in checkIdentifier #60523

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 1 addition & 2 deletions src/compiler/checker.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30525,8 +30525,7 @@ export function createTypeChecker(host: TypeCheckerHost): TypeChecker {
const initialType = isAutomaticTypeInNonNull ? undefinedType :
assumeInitialized ? (isParameter ? removeOptionalityFromDeclaredType(type, declaration as VariableLikeDeclaration) : type) :
typeIsAutomatic ? undefinedType : getOptionalType(type);
const flowType = isAutomaticTypeInNonNull ? getNonNullableType(getFlowTypeOfReference(node, type, initialType, flowContainer)) :
getFlowTypeOfReference(node, type, initialType, flowContainer);
const flowType = getFlowTypeOfReference(node, type, initialType, flowContainer);
// A variable is considered uninitialized when it is possible to analyze the entire control flow graph
// from declaration to use, and when the variable's declared type doesn't include undefined but the
// control flow based type does include undefined.
Expand Down
14 changes: 14 additions & 0 deletions tests/cases/fourslash/wrongEvolvingTypeUnderNonNullAssertion.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
/// <reference path="fourslash.ts" />

// Issue #60514

// @strict: true
//// declare function foo(): number | undefined
//// let x;
//// x = foo();
//// let [|y2|] = [|x|]!;

const [afterAssertion, beforeAssertion] = test.ranges()

verify.typeAtLocation(beforeAssertion, "number | undefined")
verify.typeAtLocation(afterAssertion, "number")