Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to avoid the error Expected 1 argument but got 0 on Typescript

This is my JavaScript function

function movements(remove) {
    var op = remove ? 'remove' : 'add';
    crossvent[op](documentElement, 'selectstart', preventGrabbed); // IE8
    crossvent[op](documentElement, 'click', preventGrabbed);
}     function move(value) {

And this is how it's called

movements();

You can find reference for in jkanban.js file.

Now I have to change it to Typescript and I got this error on function calling,

Expected 1 arguments, but got 0

How can I resolve this problem in typescript ?

like image 980
Steven Sann Avatar asked Jan 11 '19 09:01

Steven Sann


Video Answer


2 Answers

Simply add the question mark to the argument that requires your function, example:

function movements(remove?) {
    // ...
}
like image 124
Alexander Shishov Avatar answered Oct 23 '22 08:10

Alexander Shishov


You need to specify the input for calling movements().

You can set default to the variable using this:

function movements(remove = null) {

so that the function won't break even if you don't give it the input.

You can default it to anything you like though.

like image 2
holydragon Avatar answered Oct 23 '22 09:10

holydragon