Transitioning from .js
to typescript
. When I changed the file extension from .js
to .ts
while keeping the same code, I encountered an error stating
Property 'then' does not exist on type 'Text'.ts
in the then((value)
method.
The return type of getIDHome()
is 'Text
'. I'm puzzled why then((value)
does not support the return type Text
in .ts
when it worked fine in the .js
file. Any assistance in resolving the issue with then
would be appreciated.
Script at ../support/PageObject/Home.ts
:
getID(){
cy.wait(3000)
return new Cypress.Promise((resolve, reject) => {
cy.getIDHome(Row, ID).then((value)=>{
Cypress.env('ID', value.toString());
cy.log(Cypress.env('ID')+' :: adding ID in globale variable ')
resolve(value.toString());
})
})
}
https://i.sstatic.net/2MX7q.png
Custom command at ../support/commands.js
:
Cypress.Commands.add('getIDHome', (Row, ID) => {
cy.get('[class^="'+Row+'"]').then($Container=>{
const isID = $Container.find('[class^="'+ID+'"]', {timeout:2000}).get(0)
cy.wrap(isID.innerText);Text
})
Import custom command at ../support/index.js
:
import './commands'
Declare custom command at ../support/index.ts
:
declare namespace Cypress{
interface Chainable<Subject = any>{
getHome( Row: String , ID: String):Text;
} }