microsoft / microsoft/TypeScript

Emit errors for rogue jsdoc tags

Open
#53,104 0 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Awaiting More Feedback Suggestion
Dominant language
Go
Stars
111k
Forks
14.3k
Avg merge
1d 19h
Merged PRs (30d)
117

Description

Suggestion

🔍 Search Terms

List of keywords you searched for before creating this issue. Write them down here so that others can find this suggestion more easily and help provide feedback.
jsdoc rogue type tag

✅ Viability Checklist

My suggestion meets these guidelines:

  • This wouldn't be a breaking change in existing TypeScript/JavaScript code
  • This wouldn't change the runtime behavior of existing JavaScript code
  • This could be implemented without emitting different JS based on the types of the expressions
  • This isn't a runtime feature (e.g. library functionality, non-ECMAScript syntax with JavaScript output, new syntax sugar for JS, etc.)
  • This feature would agree with the rest of TypeScript's Design Goals.

⭐ Suggestion

Emit an error for jsdoc tags that have an unusual or unexpected position.

📃 Motivating Example

Say you want to cast a value but you forget the brackets around the value you want to cast:

const x = /** @type {you can pretty much type anything here} */ 3;

At the moment no error is emitted at all, but it seems like this shouldn't be legal.

💻 Use Cases

/**
 * @param {any} data
 */
function sanitizeData(data) {
    // ... sanitize
    return /** @type {SanitizedType} */ data;
}

It's easy to miss that this function has any as return type, rather than the SanitizedType you'd expect.


Note that even though this would be a breaking change, this change would likely only highlight code that was already broken and not type safe, rather than introduce new issues.

Related #47222

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Review the suggested JSDoc examples and related issue #47222 first, then trace how JSDoc tags in JavaScript are currently accepted. The change is complete when unusual or unexpected tag positions produce diagnostics without changing runtime output, with coverage for the cast and function examples.

Written by the indexing model from the issue text.

Assessment

Tech stack
javascript, typescript
Domain
compilers
Issue type
Feature
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.