cucumber-js
cucumber-js copied to clipboard
narrow down typing for hook and step functions
🤔 What's the problem you're trying to solve?
The TypeScript typings for the functions users pass in to hooks and steps should have the return value appropriately typed so it's clear what you can and can't influence from the function.
Currently the return value for all of them is typed as
any | Promise<any>
We should make these more specific.
We should also check the signature of the callback function for that style of step, for the same reason.
✨ What's your proposed solution?
Here's what I think each function should be able to return (in each case it could be a plain value of this type, or a promise that resolves to one).
-
BeforeAll
,AfterAll
-void
-
Before
,BeforeStep
-void | 'skipped'
- (actual steps) -
void | 'skipped' | 'pending'
-
AfterStep
,After
-void
This would be a breaking change technically because it would make the TypeScript types more restrictive. As such we should do it in a major release.
📚 Any additional context?
Originally discussed in https://github.com/cucumber/cucumber-js/pull/2038#discussion_r869729192