Closed
Description
TypeScript Version: v3.7-Beta
Search terms : narrow narrowing down type parameter closure
Code
function foo(arg: string | undefined) {
arg = arg ?? "default";
arg.length // no error
const bar = () => {
arg.length; // error
}
}
Expected behavior:
arg should be of type string within the body of the closure.
Actual behavior:
arg is possibly 'undefined' within the body of the closure.
Playground Link: Playground link
Metadata
Metadata
Assignees
Labels
No labels