@@ -88,16 +88,16 @@ function parseMaybeTags(tags?: string): Node {
8888 return tags ? parse ( tags ) : noopNode ;
8989}
9090
91- export class Registry {
91+ export class Registry < C extends Mocha . Context , T extends unknown [ ] > {
9292 public parameterTypeRegistry : ParameterTypeRegistry ;
9393
9494 private preliminaryStepDefinitions : {
9595 description : string | RegExp ;
96- implementation : ( ) => void ;
96+ implementation : IStepDefinitionBody < T , C > ;
9797 position ?: Position ;
9898 } [ ] = [ ] ;
9999
100- public stepDefinitions : IStepDefinition < unknown [ ] , Mocha . Context > [ ] = [ ] ;
100+ public stepDefinitions : IStepDefinition < T , C > [ ] = [ ] ;
101101
102102 private preliminaryHooks : Omit < ICaseHook , "id" > [ ] = [ ] ;
103103
@@ -151,7 +151,10 @@ export class Registry {
151151 }
152152 }
153153
154- public defineStep ( description : string | RegExp , implementation : ( ) => void ) {
154+ public defineStep (
155+ description : string | RegExp ,
156+ implementation : IStepDefinitionBody < T , C > ,
157+ ) {
155158 if ( typeof description !== "string" && ! ( description instanceof RegExp ) ) {
156159 throw new Error ( "Unexpected argument for step definition" ) ;
157160 }
@@ -281,7 +284,7 @@ export class Registry {
281284 }
282285
283286 public runStepDefinition (
284- world : Mocha . Context ,
287+ world : C ,
285288 text : string ,
286289 dryRun : boolean ,
287290 argument ?: DataTable | string ,
@@ -290,7 +293,7 @@ export class Registry {
290293
291294 const args = stepDefinition . expression
292295 . match ( text ) !
293- . map ( ( match ) => match . getValue ( world ) ) ;
296+ . map ( ( match ) => match . getValue ( world ) ) as T ;
294297
295298 if ( argument ) {
296299 args . push ( argument ) ;
@@ -375,26 +378,31 @@ export class Registry {
375378const globalPropertyName =
376379 "__cypress_cucumber_preprocessor_registry_dont_use_this" ;
377380
378- export function withRegistry (
381+ export function withRegistry < C extends Mocha . Context , T extends unknown [ ] > (
379382 experimentalSourceMap : boolean ,
380383 fn : ( ) => void ,
381- ) : Registry {
382- const registry = new Registry ( experimentalSourceMap ) ;
384+ ) : Registry < C , T > {
385+ const registry = new Registry < C , T > ( experimentalSourceMap ) ;
383386 assignRegistry ( registry ) ;
384387 fn ( ) ;
385388 freeRegistry ( ) ;
386389 return registry ;
387390}
388391
389- export function assignRegistry ( registry : Registry ) {
392+ export function assignRegistry < C extends Mocha . Context , T extends unknown [ ] > (
393+ registry : Registry < C , T > ,
394+ ) {
390395 globalThis [ globalPropertyName ] = registry ;
391396}
392397
393398export function freeRegistry ( ) {
394399 delete globalThis [ globalPropertyName ] ;
395400}
396401
397- export function getRegistry ( ) : Registry {
402+ export function getRegistry <
403+ C extends Mocha . Context ,
404+ T extends unknown [ ] ,
405+ > ( ) : Registry < C , T > {
398406 return assertAndReturn (
399407 globalThis [ globalPropertyName ] ,
400408 "Expected to find a global registry (this usually means you are trying to define steps or hooks in support/e2e.js, which is not supported)" ,
0 commit comments