Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

TypeScript Expected 1 arguments, but got 2

What’s wrong with my function createUser()?
Why I can’t put params in Smoke.ts ?

Login.ts :

interface User {
  url: string,
  email: string,
}

class Test{ 
async createUser(user: User) {
    await Page.setUrl(user.url);
    await Page.setEmail(user.email);


   
  }
}

Smoke.ts

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

test("Smoke Test", async (t) => {
  console.log("Starting test");  
  await Login.createUser(
  "google.com","joe"
  );

An error appear : Expected 1 arguments, but got 2.

>Solution :

The method createUser is expecting an object with the following shape:
{
url: string,
email: string,
}

And you are passing a string as first parameter and another string as the second parameter.

you should be passing an abject like this:

createUser({ 
   url: 'google.com', 
   email: 'joe' 
})

BTW why are you using "interface" and not "type" here?
type is more common for defining object shapes and interface is often used to describe behaviours

Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading