Search code examples
javascriptobjecttypesjsdoc

How to set Object's values as a type in JSDoc


I have an object like this :

const logTypes = {
    debug: '35',
    log  : '37',
    info : '34',
    warn : '33',
    error: '31'
}; // Don't pay attention to the values, it's for a specific system.

And I want a function that takes one of the value in argument with JSDoc.
I tried @param {logTypes} logType but it doesn't seem to be working.

What am I missing ?


Solution

  • const logTypes = {
      debug: '35',
      log: '37',
      info: '34',
      warn: '33',
      error: '31',
    };
    
    /**
     * @type {( type: keyof typeof logTypes ) => void}
     */
    const log = () => {};
    

    enter image description here