Problem with error "Invalid number of arguments, expected 0" when calling javascript method .toString(16)

Hi Folks,

My webstorm reports "Invalid number of arguments, expected 0" on the following code:

let hex = number.toString(16);

Yet the native .toString() method allows an optional radix parameter:

https://developer.mozilla.org/de/docs/Web/JavaScript/Reference/Global_Objects/Number/toString 

numObj.toString([radix])

Is there a way to disable the reportin on errors regarding only the toString-method in the IDE?

Or am I maybe making some other mistake?

 

Thanks for any help :)

 

Using WebStorm 2017.1.2
Build #WS-171.4249.40, built on April 25, 2017
JRE: 1.8.0_112-release-736-b21 amd64
JVM: OpenJDK 64-Bit Server VM by JetBrains s.r.o
Windows 10 10.0

4
11 comments
Avatar
Permanently deleted user

Update:

this was actually a flaw in my code.

the .toString() methhod only allows a radix parameter on numbers not on other variable types.

var str = "16";
var hstr = str.toString(16); // causes the warning
// Result: '16'
// not what I actually expected

var num = 16;
var hnum = num.toString(16); // causes no warning
// Result: '10'
// what I actually expected

so the warning is just fine as it is :)

2
Avatar
Permanently deleted user

> the .toString() methhod only allows a radix parameter on numbers not on other variable types.

Not only numbers

buffer.toString([encoding[, start[, end]]])

Node 8 docs

2

you have to let WebStorm know explicitly what buffer type is

/**
* @type {Buffer}
*/
let buffer;
buffer.toString(`base64`)

and, of course, Node.js Core library has to be enabled;

otherwise, Object toString() definition will be used

0
Avatar
Permanently deleted user

@Elena Pogorelova Why do we have to do anything? It's terrible IDE comparing to VS Code. Why we cannot exclude this and other warnings that is wrong by clicking in more actions? Why there's no such option?

1

How to disable it? I see it in vuex action inside of, for example in method: `vuexContext.commit('SET_PLAYERS_LIST', result)`,

0

You can suppress it for statement using comments, like

// noinspection JSCheckFunctionSignatures
const data54 = buffer.toString(`base64`)
1
Avatar
Permanently deleted user

I'm getting similar warning by creating new Map() - Invalid number of arguments, expected 1. Why is that I must provide arguments for creating Map? 

0

@Plart can't reproduce - no errors are shown for me

Can you repeat the issue in a new project?

0
Avatar
Permanently deleted user

Elena Pogorelova

Created new project (see screenshot with options), created empty test.js  -  the same (see screenshot)

0

can't reproduce:

 

please try ctrl+clicking on Map() in

const map = new Map();

- what definition are you taken to?

0
Avatar
Permanently deleted user

Problem has gone after updating to 2021.1 version

0

Please sign in to leave a comment.