-
Notifications
You must be signed in to change notification settings - Fork 13.2k
Open
Labels
Experience EnhancementNoncontroversial enhancementsNoncontroversial enhancementsSuggestionAn idea for TypeScriptAn idea for TypeScript
Description
Bug Report
🔎 Search Terms
- refactor
- refactoring
🕗 Version & Regression Information
4.8.0-dev.20220616, not a regression
💻 Code
function doThing(x: number | string) {
if (typeof x === 'string') {
x.charCodeAt(0); // Run extract to inner function here
}
}🙁 Actual behavior
The resulting code is invalid:
function doThing(x: number | string) {
if (typeof x === 'string') {
newFunction();
}
function newFunction() {
x.charCodeAt(0); // Error here: x is of type number | string
}
}🙂 Expected behavior
We either don't offer the refactoring in this case or we somehow pass the narrowed type to the function
Reactions are currently unavailable
Metadata
Metadata
Assignees
Labels
Experience EnhancementNoncontroversial enhancementsNoncontroversial enhancementsSuggestionAn idea for TypeScriptAn idea for TypeScript