Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

172
Views
jsdoc to auto use description field

I have an object like this:

resource.foo= {
  name: "Foo",
  desc: "Some description"
}

I find myself writing:

/**
 * Some description
 */
resource.foo= {
  name: "Foo",
  desc: "Some description"
}

Anyway to get the desc field automatically without copying and pasting?

about 4 years ago · Juan Pablo Isaza
2 answers
Answer question

0

Here is another way to do it, with a keybonding. Using an extension I wrote, Find and Transform, put this into your keybindings.json:

{
  "key": "alt+d",                   // whatever keybinding you want
  "command": "findInCurrentFile",
  "args": {
    "preCommands": [
      "editor.action.jumpToBracket",
      "editor.action.selectToBracket",
      "editor.action.clipboardCopyAction",
      "editor.action.insertLineBefore"
    ],
    "replace": [
      "$${",
        "return `/**\n * ` + ${CLIPBOARD}.desc  + `\n */`",
      "}$$",
    ],
    "postCommands": "cancelSelection"
  }
}

You can run javascript in the replace, and yours is pretty easy:

${CLIPBOARD}.desc since the clipboard will be the object.

jsdoc with description from object

Note the cursor must be somewhere inside the object - that is, within the brackets/braces.

about 4 years ago · Juan Pablo Isaza Report

0

Sounds impossible to me. But if all you need is to show the description in VS Code's hints, here is the closest possible solution I could come up with:

const resource = {}

const desc = 'Some description'

resource.foo= {
  name: "Foo",
  /** @type {desc} */ desc,
}

First declare desc as a constant, and you'll be able to reference the constant type. Now you should be able to see the description shows in VS Code's type hints:

enter image description here

When you are trying to type resource.foo.desc you'll also see the description:

enter image description here

about 4 years ago · Juan Pablo Isaza Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!