/** * * @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
The following would do the trick. Just use @template to type it as a generic function.
@template
/** * @template {string} K * @template T * @param {K} key * @param {T} value * @returns {Record<K, T>} */ const set = (key, value) => { return {[key]: value} }