Hacker News new | ask | show | jobs
by syspec 1039 days ago
Agree, any complex types just get placed in their own `.d.ts` file, and import that into JSDoc comments

  /// Top of file usually
  /**
   * @typedef {import('./typedefs/MyThing')} MyThing
   */
  
  /// Later
  
  /**
   * @param {MyThing} x
   */
  function(x) {
    //
  }
1 comments

Worth noting that you can also do this from plain .js files.

    /** @param { import('./foo.js').SomeType } arg */
    function doThing(arg) {
        // ...
    }
The thing being imported can be a JS thing like an exported class, or a JSDoc type that's defined with @typedef.