Javascript: typing of variables

Hi,

I have a question about the following snippet:

Is it possible to get a warning in line 2, where I assign a string to a variable that is seemingly meant for a number. Without specifying the type explicitly with a jsDoc-comment?

Thank you!

 

0
3 comments

This is a perfectly valid JavaScript, so the only way to get a warning is specifying the type explicitly with JSDoc:

/**
*
* @type {number}
*/
let i = 1;
i = "foo"
0

Thank you. I have a feature request then :-)

"Infer strict variable types from usage"

Wrong:
let i = 0;
i = "foo";

Correct:
let i = 0;
i = 1;
i = null;

Wrong:
let i = null;
i = 1;
i = "foo";

With the types: boolean, number, string, date, array, object.

Default-severity: hint (I would probably set it to error for my projects).

0

Please feel free to file a request for this feature to youtrack, https://youtrack.jetbrains.com/issues/WEB

0

Please sign in to leave a comment.