Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Resolve @typedef imports from local and/or external files #213

Open
2 tasks done
lukethacoder opened this issue May 18, 2023 · 2 comments
Open
2 tasks done

Resolve @typedef imports from local and/or external files #213

lukethacoder opened this issue May 18, 2023 · 2 comments

Comments

@lukethacoder
Copy link

Checklist

  • Did you run the analyzer with the --dev flag to get more information?
  • Did you create a minimal reproduction in the playground?

Playground Reproduction

Expected behavior

Attempting to resolve external @typedef definitions.

/**
 * A number, or a string containing a number.
 * @typedef {Object} NumberLike
 * @prop {number} Number to return 
 */

/**
 * A number, or a string containing a number.
 * @typedef {import('./NumberLikeTypes.js').NumberLike} NumberLikeExternal
 */

export default class MyElement {
    /**
     * Set the magic number (using a local @typedef annotation).
     * @param {(number|string)} x - The magic number.
     * @returns {NumberLike} - The magic number.
     */
    setMagicNumber(x) {
        return {
            number: x
        }
    }
    
    /**
     * Set the magic number (using an external @typedef annotation).
     * @param {(number|string)}
     * @returns {NumberLikeExternal} - The magic number.
     */
    setMagicNumberExternal(x) {
        return {
            number: x
        }
    }
}
// NumberLikeTypes.js
/**
 * A number, or a string containing a number.
 * @typedef {Object} NumberLike
 * @prop {number} Number to return 
 */

Output

{
  "schemaVersion": "1.0.0",
  "readme": "",
  "modules": [
    {
      "kind": "javascript-module",
      "path": "src/my-element.js",
      "declarations": [
        {
          "kind": "class",
          "description": "A number, or a string containing a number.",
          "name": "MyElement",
          "members": [
            {
              "kind": "method",
              "name": "setMagicNumber",
              "parameters": [
                {
                  "name": "x",
                  "description": "The magic number.",
                  "type": {
                    "text": "(number|string)"
                  }
                }
              ],
              "description": "Set the magic number (using a local @typedef annotation).",
              "return": {
                "type": {
                  "text": "NumberLike"
                }
              }
            },
            {
              "kind": "method",
              "name": "setMagicNumberExternal",
              "parameters": [
                {
                  "name": "x"
                },
                {
                  "name": "",
                  "type": {
                    "text": "(number|string)"
                  }
                }
              ],
              "description": "Set the magic number (using an external @typedef annotation).",
              "return": {
                "type": {
                  "text": "NumberLikeExternal"
                }
              }
            }
          ]
        }
      ],
      "exports": [
        {
          "kind": "js",
          "name": "default",
          "declaration": {
            "name": "MyElement",
            "module": "src/my-element.js"
          }
        }
      ]
    }
  ]
}

Hoping that NumberLikeExternal and NumberLike could be resolved to show the actual types, not just the string text of them.

@thepassle
Copy link
Member

Can yu clarify the issue? This CEM output looks correct to me.

@kwickramasekara
Copy link

I'm also curious if this is possible. In my case, Im expecting NumberLike to resolve to "'foo' | 'bar'" given its defined as export type NumberLike = 'foo' | 'bar';

See return type:

"declarations": [
  {
    "kind": "class",
    "description": "A number, or a string containing a number.",
    "name": "MyElement",
    "members": [
      {
        "kind": "method",
        "name": "setMagicNumber",
        "parameters": [
          {
            "name": "x",
            "description": "The magic number.",
            "type": {
              "text": "(number|string)"
            }
          }
        ],
        "description": "Set the magic number (using a local @typedef annotation).",
        "return": {
          "type": {
            "text": "'foo' | 'bar'"
          }
        }
      }
    ]
  }
]

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants