// *** before: ***
function getUrl(url: string | undefined) {
if (url === undefined) {
url = "https://example.com";
}
return () => {
console.log(url.toUpperCase()); // <-Error: inside the closure url is
//string | undefined again
};
}
// *** in version 5.4: ***
function getUrlNarrowed(url: string | undefined) {
if (url === undefined) {
url = "https://example.com";
}
return () => {
console.log(url.toUpperCase()); // OK: TS sees that url is never
//reassigned
};
}