microsoft / microsoft/TypeScript

Language server: Recursively auto-complete default object instance.

Open
#42,084 4 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Awaiting More Feedback Suggestion
Dominant language
Go
Stars
111k
Forks
14.3k
Avg merge
2d 4h
Merged PRs (30d)
132

Description

Suggestion

🔍 Search Terms

  • auto complete typescript object recursively
  • typescript language server options
  • typescript set default nested object

✅ Viability Checklist

My suggestion meets these guidelines:

  • This feature would agree with the rest of TypeScript's Design Goals.

  • This wouldn't be a breaking change in existing TypeScript/JavaScript code

  • This wouldn't change the runtime behavior of existing JavaScript code

  • This could be implemented without emitting different JS based on the types of the expressions

  • This isn't a runtime feature (e.g. library functionality, non-ECMAScript syntax with JavaScript output, new syntax sugar for JS, etc.)

⭐ Suggestion

Is it possible to add an auto complete feature to the language server that allows starting with this code:

const o: Animal = {
// Place cursor here
}

And then offering to set all keys recursively to a default value:

const o: Animal = {
    name: "",
    age: 0,
    children: [],
    mostFamousCousin: {
        name: "",
        age: 0,
        children: []
    }
}

I'm using Webstorm, which has this feature for other typed languages.

This comes in useful when you are entering data directly into large nested data types.

Thanks.

📃 Motivating Example

  • "Save yourself hours of work filling in each field of an object by auto completing the whole tree".

💻 Use Cases

  • When creating a large nested object it would be much faster to create the whole tree of objects.
  • For branching at enum points (one of many possible types) or recursive definitions, the auto complete code should end the recursion as early as possible, in which case the user can create the root object and type of their desired type for that branch and repeat the auto complete process.

Related

  • https://youtrack.jetbrains.com/issue/WEB-39222
    • IntelliJ's "Implement members" feature already completes all keys, but it has some issues with nested object literals, and when all keys are optional.
    • This feature proposes integrating the same "implement members" feature of IntelliJ into the TS lang server so it works in all editors flawlessly.

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

Start by reviewing the TypeScript language server's completion behavior and the related IntelliJ “Implement members” feature described in the issue. Done should provide recursive default-value completion for nested object literals, while stopping recursion for recursive definitions and handling enum branches as described.

Written by the indexing model from the issue text.

Assessment

Tech stack
typescript
Domain
devtools
Issue type
Feature
Difficulty
5/5
Estimated time
Over a week
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.