最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

JSDoc - how to check types for JavaScript in Eclipse? - Stack Overflow

programmeradmin5浏览0评论

I am applying JSDoc annotations:

/**
 * @param {number} millis
 * @param {function} callback
 * */
function sleep(millis, callback) {
    setTimeout(function() {
        callback();
    }, millis);
}

Then what tool would tell there is an error for line below?

sleep('aaa', 'sdsdsd');

Is JSHint aware of JSDoc type annotations? How to enable such support in Eclipse?

I am applying JSDoc annotations:

/**
 * @param {number} millis
 * @param {function} callback
 * */
function sleep(millis, callback) {
    setTimeout(function() {
        callback();
    }, millis);
}

Then what tool would tell there is an error for line below?

sleep('aaa', 'sdsdsd');

Is JSHint aware of JSDoc type annotations? How to enable such support in Eclipse?

Share Improve this question edited Apr 24, 2024 at 15:22 ggorlen 58k8 gold badges114 silver badges157 bronze badges asked Mar 6, 2014 at 8:29 Paul VerestPaul Verest 64.1k53 gold badges225 silver badges353 bronze badges 4
  • As a plement I remend using github.eclipsesource./jshint-eclipse, it will give you JsHint warnings inside the js editor. – Christophe Roussy Commented Sep 17, 2014 at 10:15
  • I would like to support this feature. See github./angelozerr/tern-lint/issues/32 it will work with Eclipse but with Emacs and Atom soon – Angelo Commented May 19, 2015 at 11:33
  • I have created an issue to support that with tern-lint (which is used inside Eclipse with tern.java) github./angelozerr/tern-lint/issues/42 I will implement soon that – Angelo Commented Jun 12, 2015 at 15:29
  • Related, practically a dupe (other than the Eclipse mention): How to validate / check types using JSDoc? – ggorlen Commented Apr 24, 2024 at 14:45
Add a ment  | 

4 Answers 4

Reset to default 4

jshint is not aware of jsdoc ments. You could however look at using eslint and writing a plugin for it that would perform type checking on function calls. Depending on how your project is set up you might end up having to pre-parse your code to extract the ments into a rules file that your eslint rule would use.

Disclaimer, I'm the author of tern.java.

I suggest you that you install tern.java 1.0.0-SNAPSHOT. It provides the capability to validate your JavaScript files by using JSDoc annotations. Here a screenshot with the sample of this issue :

If you need improvement with JSDoc validation, please create issues here

You can take a look at https://github./yarax/typelint

It's an EsLint plugin that does type check for JSDoc ments, and in addition supports it's own extension to use Redux state or Swagger schemas (basically any JSON schema) for type check.

It helps not to write plex posite types from scratch and use existing data.

now VsCode can easily do that. there are 2 ways to activate vscode's typechecking based on jsDocs .

  1. ment // @ts-check at the top of the file you want it to be checked.
  2. to actiavete it for all files, create a file named jsconfig.json at the root of your project which contains the following: { "pilerOptions": { "checkJs":true } }

now enjoy type errors!

发布评论

评论列表(0)

  1. 暂无评论