Skip to content

Fix invalid decorator examples in lib.decorators.d.ts - #64353

Open
Fatih Çakır (wfatih) wants to merge 1 commit into
microsoft:mainfrom
wfatih:fix-decorator-jsdoc-examples
Open

Fatih Çakır (wfatih) wants to merge 1 commit into
microsoft:mainfrom
wfatih:fix-decorator-jsdoc-examples

Conversation

@wfatih

Copy link
Copy Markdown

Fixes #54338
Fixes #54099

Problem

Both @example blocks in lib.decorators.d.ts reference types that do not exist in any lib file:

  • ClassDecoratorContext.addInitializer annotates the returned decorator as ClassDecoratorFunction
  • ClassMethodDecoratorContext.addInitializer annotates bound as ClassMethodDecoratorFunction

Neither name is declared anywhere in the repository (git grep finds only these two comments), so both snippets fail with Cannot find name '...'. The second snippet is additionally not parseable — const bound: ClassMethodDecoratorFunction = (value, context) { ... } is missing the => — so it cannot be pasted into an editor as-is.

Change

Both snippets are rewritten in terms of the context types this file actually declares:

  • the class-decorator example is now a decorator factory generic over Class extends CustomElementConstructor, with the element class extending HTMLElement so customElements.define(name, this) is valid;
  • the bound example is now a generic function declaration taking value: Value and context: ClassMethodDecoratorContext<This, Value>, with the dynamic member access done through an explicit Record<PropertyKey, any> view of this.

Behaviour of the examples is unchanged; only the annotations and the syntax error are fixed.

Verification

  • Both snippets compile with no errors under tsc --strict --target es2022 --lib es2022,dom --noEmit.
  • ClassDecoratorFunction / ClassMethodDecoratorFunction occur nowhere else in the repo, and tsc/internal/bundled/libs/** is excluded from dprint, so no baselines or formatting output change.

AI assistance disclosure

Per CONTRIBUTING.md: this patch was authored with AI assistance (Claude Code). I chose this specific issue, read and verified the resulting change myself, and I will be the one responding to review feedback.

Copilot AI balanced review requested due to automatic review settings September 19, 2026 17:47
@github-project-automation github-project-automation Bot moved this to Not started in PR Backlog Sep 19, 2026
@typescript-automation typescript-automation Bot added the For Backlog Bug PRs that fix a backlog bug label Sep 19, 2026

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copilot wasn't able to review any files in this pull request.


💡 Add a code-review agent skill for context-aware, tailored reviews. Learn more in the docs.

The `@example` blocks on `ClassDecoratorContext.addInitializer` and
`ClassMethodDecoratorContext.addInitializer` referenced two types that do
not exist: `ClassDecoratorFunction` and `ClassMethodDecoratorFunction`.
The second example was also syntactically invalid (a function expression
without `=>`), so neither snippet could be copied into an editor.

Rewrite both snippets so they type check under `--strict` using the
decorator context types that actually ship in this file.

Fixes microsoft#54338
Fixes microsoft#54099
@wfatih

Copy link
Copy Markdown
Author

@microsoft-github-policy-service agree

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

For Backlog Bug PRs that fix a backlog bug

Projects

Status: Not started

2 participants