最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

javascript - TypeScript Expected 1 arguments, but got 2 - Stack Overflow

programmeradmin3浏览0评论

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

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

An error appear : 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

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

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

Share Improve this question asked Dec 15, 2021 at 7:35 wewe wewewewe wewe 412 silver badges8 bronze badges 1
  • 1 createUser() is expecting a User object as parameter. But you're passing two strings. What you want would be Login.createUser({ url: "google.", email: "joe" }); – Hao Wu Commented Dec 15, 2021 at 7:38
Add a ment  | 

2 Answers 2

Reset to default 4

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 object like this:

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

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

your createUser function was declared with only one parameter but when you call this method you passed two-parameter. to fix this you need to pass user object

发布评论

评论列表(0)

  1. 暂无评论