Reputation: 113
I am trying to chain multiple methods in a class but getting this error when the second method is chained.
Property 'welcome' does not exist on type 'void'.ts(2339)
class a
hello() {
cy.log('hello');
return new b();
}
class b
export class b {
constructor(public readonly element: locator = locator) { }
world(): void {
cy.log('world');
}
welcome(): void {
cy.log('welcome');
}
class c
a.hello()
.world()
.welcome(); //getting error at this line
Upvotes: 1
Views: 21
Reputation: 4199
You need to return the instance in each method to do that.
export class CallPage {
constructor(public readonly element: locator = locator) { }
world(): CallPage {
cy.log('world');
return this;
}
welcome(): CallPage {
cy.log('welcome');
return this;
}
}
Upvotes: 1