microsoft / microsoft/TypeScript

JSDoc type aliases aren't parsed or bound at the end of blocks

Open
#54,043 0 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

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

Description

Bug Report

Followup to #54037 and #53624
This is not a regression, and fixing it would require

  • the parser to check for jsdoc before each close brace
  • the ast to store optional jsdoc on each close brace, and store the close brace on each block
  • the binder to visit each close brace to check for jsdoc to bind

So I think it's too expensive for a feature that nobody has noticed missing until recently.

🔎 Search Terms

JSDoc type alias ignored

🕗 Version & Regression Information
  • This is the behavior in every version I tried
💻 Code
// @filename: typedefAtEndOfBlock.js
// @checkJs: true
// @outdir: dist
// @declaration: true
function f() {
  /* @type {A} */
  var a = 2
  /** @typedef {string} A */
}
{
  /* @type {B} */
  var b = 2
  /** @typedef {string} B */
}
export class Class {
  /* @type {C} */
  c = 1
  /** @typedef {string} C */
}
const Dlass = class {
  /* @type {D} */
  d = 1
  /** @typedef {string} D */
}
🙁 Actual behavior

None of the typedefs are parsed or bound.

🙂 Expected behavior

The typedefs are parsed and bound.
(And none are visible outside their containers, which is not true for classes right now).

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

Start with the typedefAtEndOfBlock.js reproduction and trace how the parser, AST, and binder handle JSDoc before closing braces. Compare the behavior described in #54037 and #53624. Done means the typedefs are parsed and bound within their containers, with the documented class visibility behavior addressed.

Written by the indexing model from the issue text.

Assessment

Tech stack
javascript, typescript
Domain
compilers
Issue type
Bug
Difficulty
5/5
Estimated time
Over a week
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
25/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.