Why does TS stops me from defining my own type when using alias? "TS2769: No overload matches this call" #9525
-
I'm trying to use an alias, as mentioned in https://docs.cypress.io/guides/core-concepts/variables-and-aliases.html#Sharing-Context The issue is with this part of the code, I must use it(`should have "window.${CYPRESS_WINDOW_NS}.customer.ref" defined`, () => {
// @ts-ignore
cy.get('@customer').then((customer: Customer) => {
assert.isDefined(customer.ref);
});
}); The test runs fine regardless of the TS error. Is it a typing issue or should I declare my type differently? Full code: import { Customer } from '../../../../src/types/data/Customer';
import { CYPRESS_WINDOW_NS } from '../../../../src/utils/testing/cypress';
describe('Sanity checks > Browser data', () => {
/*
* Visits the home page before any test
*/
beforeEach(() => {
cy.visit('/en');
cy.window().then((window) => {
const {
customer,
dataset,
} = window[CYPRESS_WINDOW_NS];
// Use aliases to make our variables reusable across tests - See https://docs.cypress.io/guides/core-concepts/variables-and-aliases.html#Sharing-Context
cy.wrap(window[CYPRESS_WINDOW_NS]).as('__CYPRESS_DATA__');
cy.wrap(customer).as('customer');
cy.wrap(dataset).as('dataset');
});
});
it(`should have "window.${CYPRESS_WINDOW_NS}" defined`, () => {
assert.isDefined(cy.get('@__CYPRESS_DATA__'));
assert.isDefined(cy.get('@customer'));
assert.isDefined(cy.get('@dataset'));
});
it(`should have "window.${CYPRESS_WINDOW_NS}.customer.ref" defined`, () => {
// @ts-ignore
cy.get('@customer').then((customer: Customer) => {
assert.isDefined(customer.ref);
});
});
}); |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment
-
Answer: cy.get<Customer>('@customer').then((customer: Customer) => {
assert.isDefined(customer.ref);
});
|
Beta Was this translation helpful? Give feedback.
Answer:
get
allows a dynamic type. See:get<E extends Node = HTMLElement>(selector: string, options?: Partial<Loggable & Timeoutable & Withinable & Shadow>): Chainable<JQuery<E>>