microsoft / microsoft/TypeScript

Extract to function uses overly generic return type

Open
#52,520 1 comment 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Needs Proposal Suggestion
Dominant language
Go
Stars
111k
Forks
14.3k
Avg merge
1d 19h
Merged PRs (30d)
117

Description

Bug Report

🔎 Search Terms
  • refactor
  • extract function
🕗 Version & Regression Information

5.0.0-dev.20230130

💻 Repo
function foo(a: string | undefined): void { }

foo('a' + 'b')

Select 'a' + 'b' and run extract to function

🙁 Actual behavior

The resulting function has a return type of string | undefined

function foo(a: string | undefined): void { }

foo(newFunction())

function newFunction(): string | undefined {
    return 'a' + 'b';
}

This prevents easily re-using this function in other locations

🙂 Expected behavior

The function should have a return type of string

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Reproduce the issue with the TypeScript example by selecting 'a' + 'b' and running the extract-to-function refactoring. Start by locating the implementation and tests for that refactoring, then verify that the extracted function is inferred with a string return type rather than string | undefined.

Written by the indexing model from the issue text.

Assessment

Tech stack
typescript
Domain
tooling
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Stale
Clarity
Clearly specified
Newbie friendliness
38/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.