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

JSDoc typedef imports are emitted with a resolved path to node_modules #57954

Open
bashmish opened this issue Mar 27, 2024 · 1 comment
Open
Assignees
Labels
Bug A bug in TypeScript

Comments

@bashmish
Copy link

bashmish commented Mar 27, 2024

πŸ”Ž Search Terms

"JSDoc", "typedef", "node_modules", "resolved"

πŸ•— Version & Regression Information

  • This is the behavior in every version I tried, and I reviewed the FAQ for entries about common bugs

⏯ Playground Link

https://stackblitz.com/edit/issue-ts-jsdoc-typedef-resolved-node-modules?file=issue.js,dist-types%2Fissue.d.ts

In the StackBlitz example you can run npm run build:watch to play with the input and output of issue.js.

πŸ’» Code

/**
 * @typedef {import('@lion/ajax').LionRequestInit} LionRequestInit
 */

export class NewAjax {
  /**
   * @param {LionRequestInit} init
   */
  case1_works(init) {}

  /**
   * @param {LionRequestInit?} init
   */
  case2_works(init) {}

  /**
   * @param {LionRequestInit=} init
   */
  case3_works(init) {}

  /**
   * @type {(init?: LionRequestInit) => void}
   */
  case4_works(init) {}

  /**
   * @param {LionRequestInit} [init]
   */
  case5_unexpectedlyResolvesPathToNodeModules(init) {}
}

/**
 * @type {(init?: LionRequestInit) => void}
 */
// @ts-expect-error
NewAjax.prototype.case6_unexpectedlyResolvesPathToNodeModules;

πŸ™ Actual behavior

For some cases (case5 and case6) the emitted .d.ts files contains a path to node_modules, which is not needed and when published to NPM as part of my library will not resolve correctly.

/**
 * @typedef {import('@lion/ajax').LionRequestInit} LionRequestInit
 */
export class NewAjax {
    /**
     * @param {LionRequestInit} init
     */
    case1_works(init: LionRequestInit): void;
    /**
     * @param {LionRequestInit?} init
     */
    case2_works(init: LionRequestInit | null): void;
    /**
     * @param {LionRequestInit=} init
     */
    case3_works(init?: LionRequestInit | undefined): void;
    case4_works(init?: LionRequestInit): void;
    /**
     * @param {LionRequestInit} [init]
     */
    case5_unexpectedlyResolvesPathToNodeModules(init?: import("./node_modules/@lion/ajax/dist-types/types/types.js").LionRequestInit | undefined): void;
    /**
     * @type {(init?: LionRequestInit) => void}
     */
    case6_unexpectedlyResolvesPathToNodeModules: (init?: import("./node_modules/@lion/ajax/dist-types/types/types.js").LionRequestInit | undefined) => void;
}
export type LionRequestInit = import('@lion/ajax').LionRequestInit;

πŸ™‚ Expected behavior

case5 and case6 work the same as all others, just having methodName(init?: LionRequestInit | undefined): void;

Additional information about the issue

I'm using case6 to define method types without overriding it, because it's indirectly supporting smth that the parent class does not. So I'm intertested to make it work. Workarounds like case2-3-4 are not suitable for me.

@RyanCavanaugh RyanCavanaugh added the Bug A bug in TypeScript label Mar 27, 2024
@RyanCavanaugh RyanCavanaugh added this to the TypeScript 5.6.0 milestone Mar 27, 2024
@remcohaszing
Copy link

This happens consistently if TypeScript is unable to resolve a type from public exports based on inference.

This particular case looks different though.

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

No branches or pull requests

4 participants