Warning: session_start(): open(/tmp/sess_bd294e064c53d6ca15e31ccc0d4488f1, O_RDWR) failed: Disk quota exceeded (122) in /home/wvyrfnwn/learnshareit.com/wp-content/plugins/learnpress/inc/class-lp-page-controller.php on line 1007

Warning: session_start(): Failed to read session data: files (path: /tmp) in /home/wvyrfnwn/learnshareit.com/wp-content/plugins/learnpress/inc/class-lp-page-controller.php on line 1007

Warning: ftp_nlist() expects parameter 1 to be resource, null given in /home/wvyrfnwn/learnshareit.com/wp-admin/includes/class-wp-filesystem-ftpext.php on line 420

Warning: ftp_pwd() expects parameter 1 to be resource, null given in /home/wvyrfnwn/learnshareit.com/wp-admin/includes/class-wp-filesystem-ftpext.php on line 230

Warning: ftp_pwd() expects parameter 1 to be resource, null given in /home/wvyrfnwn/learnshareit.com/wp-admin/includes/class-wp-filesystem-ftpext.php on line 230

Warning: ftp_pwd() expects parameter 1 to be resource, null given in /home/wvyrfnwn/learnshareit.com/wp-admin/includes/class-wp-filesystem-ftpext.php on line 230

Warning: ftp_nlist() expects parameter 1 to be resource, null given in /home/wvyrfnwn/learnshareit.com/wp-admin/includes/class-wp-filesystem-ftpext.php on line 420

Warning: ftp_pwd() expects parameter 1 to be resource, null given in /home/wvyrfnwn/learnshareit.com/wp-admin/includes/class-wp-filesystem-ftpext.php on line 230

Warning: ftp_pwd() expects parameter 1 to be resource, null given in /home/wvyrfnwn/learnshareit.com/wp-admin/includes/class-wp-filesystem-ftpext.php on line 230

Warning: ftp_pwd() expects parameter 1 to be resource, null given in /home/wvyrfnwn/learnshareit.com/wp-admin/includes/class-wp-filesystem-ftpext.php on line 719

Warning: ftp_nlist() expects parameter 1 to be resource, null given in /home/wvyrfnwn/learnshareit.com/wp-admin/includes/class-wp-filesystem-ftpext.php on line 420

Warning: ftp_pwd() expects parameter 1 to be resource, null given in /home/wvyrfnwn/learnshareit.com/wp-admin/includes/class-wp-filesystem-ftpext.php on line 230

Warning: ftp_pwd() expects parameter 1 to be resource, null given in /home/wvyrfnwn/learnshareit.com/wp-admin/includes/class-wp-filesystem-ftpext.php on line 230

Warning: ftp_pwd() expects parameter 1 to be resource, null given in /home/wvyrfnwn/learnshareit.com/wp-admin/includes/class-wp-filesystem-ftpext.php on line 230

Warning: ftp_nlist() expects parameter 1 to be resource, null given in /home/wvyrfnwn/learnshareit.com/wp-admin/includes/class-wp-filesystem-ftpext.php on line 420

Warning: ftp_pwd() expects parameter 1 to be resource, null given in /home/wvyrfnwn/learnshareit.com/wp-admin/includes/class-wp-filesystem-ftpext.php on line 230

Warning: ftp_pwd() expects parameter 1 to be resource, null given in /home/wvyrfnwn/learnshareit.com/wp-admin/includes/class-wp-filesystem-ftpext.php on line 230

Warning: ftp_pwd() expects parameter 1 to be resource, null given in /home/wvyrfnwn/learnshareit.com/wp-admin/includes/class-wp-filesystem-ftpext.php on line 719

Warning: ftp_mkdir() expects parameter 1 to be resource, null given in /home/wvyrfnwn/learnshareit.com/wp-admin/includes/class-wp-filesystem-ftpext.php on line 562

Warning: ftp_nlist() expects parameter 1 to be resource, null given in /home/wvyrfnwn/learnshareit.com/wp-admin/includes/class-wp-filesystem-ftpext.php on line 420

Warning: ftp_pwd() expects parameter 1 to be resource, null given in /home/wvyrfnwn/learnshareit.com/wp-admin/includes/class-wp-filesystem-ftpext.php on line 230

Warning: ftp_pwd() expects parameter 1 to be resource, null given in /home/wvyrfnwn/learnshareit.com/wp-admin/includes/class-wp-filesystem-ftpext.php on line 230
Solution For "Expected 0 Arguments, But Got 1" Error In TypeScript - LearnShareIT

Solution For “Expected 0 Arguments, But Got 1” Error In TypeScript

Expected 0 arguments, but got 1 error in TypeScript

If you are having trouble dealing with “Expected 0 arguments, but got 1″ error in TypeScript, this article will give you a way to fix this problem. Let’s see what the information we provide in this article.

Why do we have this error?

This error occurs when you pass an input parameter to a function, but that function does not require any arguments.

Let us reproduce the error case through the following example:

function getMessage() {
    return 'Study with LearnShareIT'
}
 
const result = getMessage('Hello')
console.log(result)

Output:

Expected 0 arguments, but got 1.

As in this example, the function getMessage() is defined as a function that requires no input parameters. Passing the string ‘Hello’ as the first parameter will cause an error.

More broadly, it can be understood that this is an error caused by the user passing in the wrong number of parameters to the specific function.

How to fix the “Expected 0 arguments, but got 1” error in TypeScript?

To fix this error, ensure you pass in the correct number of arguments specified on the function.

For example, in the first example, you just need to call the function without passing any parameters to get the result.

function getMessage() {
    return 'Study with LearnShareIT'
}
 
const result = getMessage()
console.log(result)

Output:

"Study with LearnShareIT"

In case you define arguments for the function, please pass all required arguments.

// the function takes 3 arguments, one of which is optional
function birthdayWish(name: string, age: number, emotion?: string)  {
    return `You turned ${age} years old. Wish you all the best on your birthday, ${name}`
}
 
// call function birthdayWish() with different number of arguments
const result1 = birthdayWish('Long',18)
const result2 = birthdayWish('Nam',22,'Happy')
 
console.log(result1)
console.log(result2)

Output:

"You turned 18 years old. Wish you all the best on your birthday, Long"
"You turned 22 years old. Wish you all the best on your birthday, Nam" 

In this example, we create a function named birthdayWish with three input parameters. However, only two of them are required (name and age). The other one: emotion is optional

Any instance created from the function birthdayWish must have at least two arguments: name, age.

As you can see, result1 and result2 are generated from the function birthdayWish but with different numbers of parameters, but our program still works.

Summary

That’s the end of this article. We hope you understand the “Expected 0 arguments, but got 1” error in TypeScript and how to fix it. Thank you for being so interested.

Maybe you are interested:

Leave a Reply

Your email address will not be published. Required fields are marked *