You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
In order to have request and response types for the body property in calls to cy.intercept and cy.wait, I'd like to be able to specify generics for these, so that I don't have to use any in the callbacks.
Specifically:
cy.intercept<CustomRequest,CustomResponse>(url,(req)=>{req.body// ← this should be a CustomRequestreq.continue((res)=>{res.body// ← this should be a CustomResponse})})
and
cy.wait<CustomRequest,CustomResponse>('@alias').then(({ request, response })=>{request.body// ← this should be a CustomRequestresponse.body// ← this should be a CustomResponse})
Why is this needed?
While looking at converting our project to TypeScript, I was surprised that we'd have to either:
use any for the body parameter in all callbacks of intercept and wait
manually specify the interception type to get types in those calls, such as:
Instead. with the proposal above, it is marginally easier and less error prone to write:
constwhenComplete=(expectations: ((i: Interception<CustomRequest,CustomResponse>)=>void))=>cy.wait('@alias').then(expectations);whenComplete(({ request, response })=>{expect(request.body.payload).to.exist// ← here the request type is knownexpect(response?.body.data).to.exist// ← here the response type is known})
We do have these types (CustomRequest and CustomResponse as examples) already defined, so would be good if we can use them easily everywhere.
Other
I have a fork that puts a type on the core BaseMessage interface, for body. This caused all the related types to have required updates to their types (i.e. made generic too).
I might have missed a better way to think about or do this.
The text was updated successfully, but these errors were encountered:
…s-io#29507)
The nested types were apparently not supported (as written) before TypeScript ~4.1.Remove them in favour of just using `Interception<any, any>` in this overload of `wait`.
What would you like?
In order to have request and response types for the
body
property in calls tocy.intercept
andcy.wait
, I'd like to be able to specify generics for these, so that I don't have to useany
in the callbacks.Specifically:
and
Why is this needed?
While looking at converting our project to TypeScript, I was surprised that we'd have to either:
any
for thebody
parameter in all callbacks ofintercept
andwait
which still requires
as
if we want to keep full type safety.This feels especially awkward because we have wrapped some
wait
calls to their own methods:Instead. with the proposal above, it is marginally easier and less error prone to write:
We do have these types (
CustomRequest
andCustomResponse
as examples) already defined, so would be good if we can use them easily everywhere.Other
I have a fork that puts a type on the core
BaseMessage
interface, forbody
. This caused all the related types to have required updates to their types (i.e. made generic too).I might have missed a better way to think about or do this.
The text was updated successfully, but these errors were encountered: