microsoft / microsoft/TypeScript
"Extract to function" refactor is not suggested if selection contains `if` statement (conditional return)
未关闭
还没有人认领这个 Issue。
Experience Enhancement
Suggestion
- 主要语言
- Go
- 星标
- 111k
- 派生
- 14.4k
- 平均合并
- 1 天 19 小时
- 30 天内合并 PR
- 117
描述
TypeScript Version: 3.9.2
Search Terms:
Code
const fn = ({ condition }: { condition: boolean }) => {
if (condition) {
return 1;
} else {
return 2;
}
};
Select the whole if statement, including the else, like this:

Expected behavior:
The "extract to function" refactor should be suggested. When the refactor is used, it should produce code that looks like this:
const fn = ({ condition }: { condition: boolean }) => {
return newFunction(condition);
};
function newFunction(condition: boolean) {
if (condition) {
return 1;
} else {
return 2;
}
}
Actual behavior:
The "extract to function" refactor is not suggested (testing in VS Code).
Playground Link:
Related Issues:
贡献指南
从这里开始
- 先读完整个 Issue,再读项目的贡献指南。
- 在 Issue 下留言说明你要接手 —— 这能避免两个人做同样的事。
- Fork 仓库,在一个分支上完成修改。
- 提交 Pull Request,并在描述里引用这个 Issue 编号。
调研方向
在 VS Code 中使用 TypeScript 3.9.2 重现提供的 TypeScript 代码片段,选择完整的 if 语句,包括 else。调查 extract-to-function 重构的行为,并验证建议是否出现,以及是否生成 issue 中所示的预期函数提取结果。
由索引模型根据 Issue 内容生成。
评估
- 技术栈
- typescript
- 领域
- developer-experience, tooling
- Issue 类型
- 缺陷
- 难度
- 3/5
- 预计耗时
- 1-2 天
- 活跃度
- 停滞
- 描述清晰度
- 基本清楚
- 新手友好度
- 42/100