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

未关闭
#43,812 5 条评论 5 个 reaction 已指派 0 人 在 GitHub 查看

还没有人认领这个 Issue。

评估

难度
5/5
预计耗时
一周以上
新手友好度
35/100
Issue 类型
缺陷
描述清晰度
基本清楚
活跃度
冷清

调研方向

使用 JavaScript 和 TS80002 在链接的 TypeScript Playground 中重现该行为,然后调查 @this 和 @function JSDoc 提示如何影响构造函数检测。当受支持的注解或推断路径能够阻止函数被分类为构造函数,并恢复编辑器导航所需的预期函数分类时,即表示完成。

由索引模型根据 Issue 内容生成。

描述

Awaiting More Feedback Suggestion

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.

主要语言
Go
星标
111k
派生
14.4k
平均合并
1 天 19 小时
30 天内合并 PR
117

贡献指南

打开贡献指南

从这里开始

  1. 先读完整个 Issue,再读项目的贡献指南。
  2. 在 Issue 下留言说明你要接手 —— 这能避免两个人做同样的事。
  3. Fork 仓库,在一个分支上完成修改。
  4. 提交 Pull Request,并在描述里引用这个 Issue 编号。

microsoft/TypeScript 的其他 Issue

查看 microsoft/TypeScript 的全部 Issue

相似的 Issue

更多 Go Issue

把新 issue 发到你的邮箱

精选适合新手参与的 GitHub issue 摘要。