microsoft / microsoft/TypeScript

Quick fix proposal: declare property for jsdoc types

Open
#27,163 0 comments 2 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Domain: JavaScript Domain: LS: Refactorings In Discussion Suggestion
Dominant language
Go
Stars
111k
Forks
14.3k
Avg merge
2d 4h
Merged PRs (30d)
132

Description

From https://github.com/Microsoft/vscode/issues/44824

Search Terms

  • quick fix / code action
  • jsdoc / jsdocs

Suggestion

Introduce a new refactoring that introduces a property into a jsdoc type. For example, for the js:

//@ts-check

/**
 * @param {{ }} arg
 */
function doStuff(arg) {
    console.log(arg.noSuch);
}

A quick fix on noSuch would add this property to the type of arg:

//@ts-check

/**
 * @param {{noSuch: object }} arg
 */
function doStuff(arg) {
    console.log(arg.noSuch);
}

A similar refactoring already exists for typescript:

interface IFoo {
    a: number
}

function doStuff(arg: IFoo) {
    console.log(arg.noSuch);
}

screen shot 2018-09-17 at 3 43 00 pm

Use Cases

Improve experience using ts-check, especially if using complex types

Other cases to consider

typedef

//@ts-check

/**
 * @typedef {{ a: number}} IFoo
 */

/**
 * 
 * @param {IFoo} arg 
 */
function doStuff(arg) {
    console.log(arg.noSuch);
}

Augments

/**
 * @augments {Component<{}>}
 */
class Binek extends Component {
	render() {
		console.log(this.props.noSuch)
	}
}

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 with the existing TypeScript refactoring for adding an interface property and the linked VS Code issue, then compare its behavior with the JSDoc parameter, typedef, and augments examples here. Done means a quick fix can add the missing property to the relevant JSDoc type while covering the listed cases.

Written by the indexing model from the issue text.

Assessment

Tech stack
javascript, typescript
Domain
compilers
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.