简体   繁体   English

如何注释该参数是 class 并具有某些 static 方法?

[英]How can I annotate that argument is a class and has certain static method?

I want to pass a class to function and call its static method.我想将 class 传递给 function 并调用它的 static 方法。 The code works but autocomplete does not.该代码有效,但自动完成功能无效。 How can I annotate that argument has certain static method?如何注释该参数具有某些 static 方法?

class Parent {
  static staticMethod() {
    console.log("static method")
  }
}
class Child1 extends Parent {}
class Child2 extends Parent {}

/** @param {Parent} child */
function doSomething(child) {
  child.staticMethod(); // no autocomplete
}
doSomething(Child1)

在此处输入图像描述

ADDED添加

Marked as duplicate and suggested inappropriate question;标记为重复并提出不恰当的问题; it is talked about library but I ask about what happens in a single file itself.它谈到了库,但我问的是单个文件本身会发生什么。

Writing jsdoc documentation on methods inside a class 编写有关 class 内部方法的 jsdoc 文档

Use typeof :使用typeof

/**
 * @param {typeof Parent} child
 */

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 如何使用 puppeteer 检查 div 是否具有某个 class? - How can I check if a div has a certain class using puppeteer? 如果存在某个参数,如何编写需要属性的自定义错误类? - How can I write a custom error class that will require a property if a certain argument exists? 如何找到具有构造函数参数等于输入的Class的特定新对象 - How can i find specific new object of Class that has a constructor argument equal to input 使用 JSDoc 如何注释解构的重命名函数参数? - Using JSDoc how would I annotate a destructured renamed function argument? 如何将静态方法从Java类导入到Rhino中运行的JS中? Oracle实施 - How can I import a static method from Java class into JS running in Rhino? Oracle implementation 如何使用默认导出在TypeScript类型中描述JavaScript类静态工厂方法? - How can I describe a JavaScript class static factory method in TypeScript typings with default export? Class 方法返回一个自身的数组。 如何注释和继承? - Class method which returns an array of itself. How to annotate and inherit? 我可以使用原型向外部类添加非静态方法吗? - can I add non static method to external class using prototypes? 您如何判断js类方法是否是静态的? - How can you tell if a js class method is static or not? 如何在不使用indexOf方法的情况下定位具有特定内联样式的特定dom css类 - How can I target a specific dom css class that has a specific inline style without using indexOf method
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM