Skip to content

TypeScript emits incorrect type for setters in JSDocΒ #58167

@remcohaszing

Description

@remcohaszing

πŸ”Ž Search Terms

jsdoc set

πŸ•— Version & Regression Information

⏯ Playground Link

https://www.typescriptlang.org/play?ts=5.4.5&filetype=js#code/KYDwDg9gTgLgBAYwDYEMDOa4DUBiBLJYOAbwCg44B6AKmvIurgAEpgYBXKAO02LRih4uAcwC+9ONUr1hbOGBQwAFgAoAlCQlxWHbnADk++uPo06FScwVQUAWxIBVAEoAZOAB84-QSNHzFShJS9GhyCsoq4UoaZBTiJggQPPAAZgREALxwXMAA7tj4hOqkaYQAdFFwWfqUaBC2wJRRRqXAFQFV2Xlwzi4q+q0AXJQjdQ1NAfpqQA

πŸ’» Code

export class VFile {
  /**
   * @returns {string}
   */
  get path() {
    return ''
  }

  /**
   * @param {URL | string} path
   */
  set path(path) {
  }
}

const file = new VFile()
file.path = '/some/path'
file.path = new URL('file:///some/path')

πŸ™ Actual behavior

  • βœ”οΈ The setter type annotation is used for type checking the setter
  • ❌ The getter type annotation is emitted as the setter type in the .d.ts file

πŸ™‚ Expected behavior

The setter type annotation should be emitted as the setter type

Additional information about the issue

This only affects types in JSDoc. Correct types are emitted for the equivalent TypeScript code.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions