microsoft / microsoft/TypeScript
Encapsulate type refactoring
Nobody has claimed this yet.
- Dominant language
- Go
- Stars
- 111k
- Forks
- 14.3k
- Avg merge
- 2d 4h
- Merged PRs (30d)
- 132
Description
Search Terms
- refactoring
- encapsulate
- return, function
Suggestion
Add a refactoring that encapsulates a given instance of a type and updates uses of it. Encapsulating would wrap the type in an object type that has a single property of that type.
Use cases
My original use case would be to convert a single returned type to an object that can return multiple values:
- Start
function foo(): number { return Date.now(); } const z = foo(); - Select
numberand runencapsulate - Result
function foo(): { value: number } { return { value: Date.now() }; } const z = foo().value;
This could also be used for individual parameters in a function:
- Start
function foo(x: number) { return x * 2; } foo(1); - Select
numberand runencapsulate - Result
function foo(x: { value: number }) { return x.value * 2; } foo({ value: 1 });
This may fall under some larger class of refactoring, I'm just not sure what to call it
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
The issue names no files or tests; use the foo return-type and parameter examples as the acceptance cases. First inspect the repository’s existing refactoring entry points and tests. Done means an Encapsulate action transforms both a selected return type and a function parameter, updating the shown call sites to use the resulting { value: ... } shape.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- typescript
- Domain
- tooling
- Issue type
- Feature
- Difficulty
- 5/5
- Estimated time
- Over a week
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 25/100