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

166
Views
JSdoc: Dynamic key name of return object

/**
 * 
 * @param {string} key 
 * @param {any} value
 * @returns {{[key]: typeof value}} 
 */
const set = (key, value) => {
    return {[key]: value}
}

const myObj = set("country", "USA")

myObj. // should suggest .country key

I can not understand how correct define key name of return object

enter image description here

about 4 years ago · Santiago Trujillo
1 answers
Answer question

0

The following would do the trick. Just use @template to type it as a generic function.

/**
 * @template {string} K
 * @template T
 * @param {K} key
 * @param {T} value
 * @returns {Record<K, T>}
 */
const set = (key, value) => {
  return {[key]: value}
}

Screenshot

about 4 years ago · Santiago Trujillo 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!