microsoft / microsoft/TypeScript

Unable to mark JS functions as not being constructors (TS80002)

Open
#43,812 5 comments 5 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
2d 4h
Merged PRs (30d)
132

Description

Bug Report

TS80002 ("This constructor function may be turned to a class declaration") is a useful tool, but, it often breaks syntax coloring and classification of functions for things like out-of-line event handlers. There seems to be no way to mark a function as "not a constructor" (would the @function JSDoc hint maybe serve this purpose?)

🔎 Search Terms

jsdoc typescript constructor ts80002

🕗 Version & Regression Information
  • This behavior was introduced after 3.6.2 at some point, and I reviewed the FAQ for entries about TS80002.
⏯ Playground Link

Playground link with relevant code

💻 Code
/**
 * @this {HTMLElement}
 * @param {MouseEvent} e
 */
function test(e)
{
    this.textContent = '500';
}

document.addEventListener('click', test);
🙁 Actual behavior

TypeScript marks the function test as a constructor for a type. As a consequence, too, VSCode marks it as a type, and not a function, which is confusing for navigation purposes.

🙂 Expected behavior

TypeScript should be able to detect that with a @this hint (or @function perhaps?) that this isn't a constructor.

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

Reproduce the behavior in the linked TypeScript Playground with JavaScript and TS80002, then investigate how the @this and @function JSDoc hints affect constructor detection. Done means a supported annotation or inference path prevents the function from being classified as a constructor and restores the expected function classification for editor navigation.

Written by the indexing model from the issue text.

Assessment

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

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.