Skip to content

JSDoc types with class / namespace not combined correctly #48821

Description

Bug Report

The AWS-SDK has this type:

export class ManagedUpload {
  // class def
}
export namespace ManagedUpload {
    // etc
    export interface SendData {
        Location: string;
        ETag: string;
        Bucket: string;
        Key: string;
    }
}

I'm importing ManagedUpload in a TS-checked JSDoc file like:

/** @typedef {import('aws-sdk/lib/s3/managed_upload').ManagedUpload} ManagedUpload */

But referencing ManagedUpload produces an error, when used like:

      /** 
       * @param {Error} s3Err
       * @param {ManagedUpload.SendData} data
       */
      function uploadFunction(s3Err, data) {
        if (s3Err) reject(s3Err)
        resolve(data)
      }

I get an error / underline on ManagedUpload which says, 'ManagedUpload' only refers to a type, but is being used as a namespace here.

🔎 Search Terms

JSDoc, namespace, class

🕗 Version & Regression Information

Embedded TypeScript version in VSCode (1.66.0)

Activity

  1. andrewbranch commented on Apr 25, 2022

    @andrewbranch
    Member

    @typedef only declares a type; it’s an exact analog of type ManagedUpload = ... so this is expected right now. It does seem like JSDoc would benefit from some way of having a proper alias declaration. Nathan Shively-Sanders (@sandersn) thoughts?

  2. sandersn commented on Apr 29, 2022

    @sandersn
    Member

    If you really only want the nested type out of the namespace, you can already alias it directly:

    /** @typedef {import('aws-sdk/lib/s3/managed_upload').ManagedUpload.SendData} SendData */

    I'd usually expect to see a real import of a class you're using, which would work as well:

    import { ManagedUpload } from 'aws-sdk/lib/s3/managed_upload'

    Given those two options, I don't believe a third one is needed.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    Awaiting More FeedbackThis means we'd like to hear from more people who would be helped by this featureDomain: JSDocRelates to JSDoc parsing and type generationSuggestionAn idea for TypeScript

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions