Skip to content

Commit 8efb9d1

Browse files
committed
Change implementation argument type constraint to unknown
This mostly impacts macros, for which we'd want to encourage explicit types.
1 parent fadc6c8 commit 8efb9d1

File tree

2 files changed

+29
-29
lines changed

2 files changed

+29
-29
lines changed

index.d.ts

Lines changed: 27 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -401,15 +401,15 @@ export interface TeardownFn {
401401
(fn: () => void): void;
402402
}
403403

404-
export type ImplementationFn<Args extends any[], Context = unknown> =
404+
export type ImplementationFn<Args extends unknown[], Context = unknown> =
405405
((t: ExecutionContext<Context>, ...args: Args) => PromiseLike<void>) |
406406
((t: ExecutionContext<Context>, ...args: Args) => Subscribable) |
407407
((t: ExecutionContext<Context>, ...args: Args) => void);
408408

409-
export type TitleFn<Args extends any[]> = (providedTitle: string | undefined, ...args: Args) => string;
409+
export type TitleFn<Args extends unknown[]> = (providedTitle: string | undefined, ...args: Args) => string;
410410

411411
/** A reusable test or hook implementation. */
412-
export type Macro<Args extends any[], Context = unknown> = {
412+
export type Macro<Args extends unknown[], Context = unknown> = {
413413
/** The function that is executed when the macro is used. */
414414
readonly exec: ImplementationFn<Args, Context>;
415415

@@ -418,20 +418,20 @@ export type Macro<Args extends any[], Context = unknown> = {
418418
};
419419

420420
/** A test or hook implementation. */
421-
export type Implementation<Args extends any[], Context = unknown> = ImplementationFn<Args, Context> | Macro<Args, Context>;
421+
export type Implementation<Args extends unknown[], Context = unknown> = ImplementationFn<Args, Context> | Macro<Args, Context>;
422422

423423
export interface TryFn<Context = unknown> {
424424
/**
425425
* Attempt to run some assertions. The result must be explicitly committed or discarded or else
426426
* the test will fail. The title may help distinguish attempts from one another.
427427
*/
428-
<Args extends any[]>(title: string, fn: Implementation<Args, Context>, ...args: Args): Promise<TryResult>;
428+
<Args extends unknown[]>(title: string, fn: Implementation<Args, Context>, ...args: Args): Promise<TryResult>;
429429

430430
/**
431431
* Attempt to run some assertions. The result must be explicitly committed or discarded or else
432432
* the test will fail.
433433
*/
434-
<Args extends any[]>(fn: Implementation<Args, Context>, ...args: Args): Promise<TryResult>;
434+
<Args extends unknown[]>(fn: Implementation<Args, Context>, ...args: Args): Promise<TryResult>;
435435
}
436436

437437
export interface AssertionError extends Error {}
@@ -471,13 +471,13 @@ export interface TryResult {
471471

472472
export interface TestInterface<Context = unknown> {
473473
/** Declare a concurrent test. Additional arguments are passed along. */
474-
<Args extends any[]>(title: string, implementation: Implementation<Args, Context>, ...args: Args): void;
474+
<Args extends unknown[]>(title: string, implementation: Implementation<Args, Context>, ...args: Args): void;
475475

476476
/**
477477
* Declare a concurrent test that uses a macro. The macro is responsible for generating a unique test title.
478478
* Additional arguments are passed along.
479479
*/
480-
<Args extends any[]>(macro: Macro<Args, Context>, ...args: Args): void;
480+
<Args extends unknown[]>(macro: Macro<Args, Context>, ...args: Args): void;
481481

482482
/** Declare a hook that is run once, after all tests have passed. */
483483
after: AfterInterface<Context>;
@@ -506,10 +506,10 @@ export interface TestInterface<Context = unknown> {
506506

507507
export interface AfterInterface<Context = unknown> {
508508
/** Declare a hook that is run once, after all tests have passed. Additional arguments are passed along. */
509-
<Args extends any[]>(title: string, implementation: Implementation<Args, Context>, ...args: Args): void;
509+
<Args extends unknown[]>(title: string, implementation: Implementation<Args, Context>, ...args: Args): void;
510510

511511
/** Declare a hook that is run once, after all tests have passed. Additional arguments are passed along. */
512-
<Args extends any[]>(implementation: Implementation<Args, Context>, ...args: Args): void;
512+
<Args extends unknown[]>(implementation: Implementation<Args, Context>, ...args: Args): void;
513513

514514
/** Declare a hook that is run once, after all tests are done. */
515515
always: AlwaysInterface<Context>;
@@ -519,65 +519,65 @@ export interface AfterInterface<Context = unknown> {
519519

520520
export interface AlwaysInterface<Context = unknown> {
521521
/** Declare a hook that is run once, after all tests are done. Additional arguments are passed along. */
522-
<Args extends any[]>(title: string, implementation: Implementation<Args, Context>, ...args: Args): void;
522+
<Args extends unknown[]>(title: string, implementation: Implementation<Args, Context>, ...args: Args): void;
523523

524524
/** Declare a hook that is run once, after all tests are done. Additional arguments are passed along. */
525-
<Args extends any[]>(implementation: Implementation<Args, Context>, ...args: Args): void;
525+
<Args extends unknown[]>(implementation: Implementation<Args, Context>, ...args: Args): void;
526526

527527
skip: HookSkipInterface<Context>;
528528
}
529529

530530
export interface BeforeInterface<Context = unknown> {
531531
/** Declare a hook that is run once, before all tests. Additional arguments are passed along. */
532-
<Args extends any[]>(title: string, implementation: Implementation<Args, Context>, ...args: Args): void;
532+
<Args extends unknown[]>(title: string, implementation: Implementation<Args, Context>, ...args: Args): void;
533533

534534
/** Declare a hook that is run once, before all tests. Additional arguments are passed along. */
535-
<Args extends any[]>(implementation: Implementation<Args, Context>, ...args: Args): void;
535+
<Args extends unknown[]>(implementation: Implementation<Args, Context>, ...args: Args): void;
536536

537537
skip: HookSkipInterface<Context>;
538538
}
539539

540540
export interface FailingInterface<Context = unknown> {
541541
/** Declare a concurrent test. Additional arguments are passed along. The test is expected to fail. */
542-
<Args extends any[]>(title: string, implementation: Implementation<Args, Context>, ...args: Args): void;
542+
<Args extends unknown[]>(title: string, implementation: Implementation<Args, Context>, ...args: Args): void;
543543

544544
/**
545545
* Declare a concurrent test that uses a macro. Additional arguments are passed along.
546546
* The macro is responsible for generating a unique test title. The test is expected to fail.
547547
*/
548-
<Args extends any[]>(macro: Macro<Args, Context>, ...args: Args): void;
548+
<Args extends unknown[]>(macro: Macro<Args, Context>, ...args: Args): void;
549549

550550
only: OnlyInterface<Context>;
551551
skip: SkipInterface<Context>;
552552
}
553553

554554
export interface HookSkipInterface<Context = unknown> {
555555
/** Skip this hook. */
556-
<Args extends any[]>(title: string, implementation: Implementation<Args, Context>, ...args: Args): void;
556+
<Args extends unknown[]>(title: string, implementation: Implementation<Args, Context>, ...args: Args): void;
557557

558558
/** Skip this hook. */
559-
<Args extends any[]>(implementation: Implementation<Args, Context>, ...args: Args): void;
559+
<Args extends unknown[]>(implementation: Implementation<Args, Context>, ...args: Args): void;
560560
}
561561

562562
export interface OnlyInterface<Context = unknown> {
563563
/** Declare a test. Additional arguments are passed along. Only this test and others declared with `.only()` are run. */
564-
<Args extends any[]>(title: string, implementation: Implementation<Args, Context>, ...args: Args): void;
564+
<Args extends unknown[]>(title: string, implementation: Implementation<Args, Context>, ...args: Args): void;
565565

566566
/**
567567
* Declare a test that uses a macro. The macro is responsible for generating a unique test title.
568568
* Only this test and others declared with `.only()` are run.
569569
*/
570-
<Args extends any[]>(macro: Macro<Args, Context>, ...args: Args): void;
570+
<Args extends unknown[]>(macro: Macro<Args, Context>, ...args: Args): void;
571571
}
572572

573573
export interface SerialInterface<Context = unknown> {
574574
/** Declare a serial test. Additional arguments are passed along. */
575-
<Args extends any[]>(title: string, implementation: Implementation<Args, Context>, ...args: Args): void;
575+
<Args extends unknown[]>(title: string, implementation: Implementation<Args, Context>, ...args: Args): void;
576576

577577
/**
578578
* Declare a serial test that uses a macro. The macro is responsible for generating a unique test title.
579579
*/
580-
<Args extends any[]>(macro: Macro<Args, Context>, ...args: Args): void;
580+
<Args extends unknown[]>(macro: Macro<Args, Context>, ...args: Args): void;
581581

582582
/** Declare a serial hook that is run once, after all tests have passed. */
583583
after: AfterInterface<Context>;
@@ -601,26 +601,26 @@ export interface SerialInterface<Context = unknown> {
601601

602602
export interface SkipInterface<Context = unknown> {
603603
/** Skip this test. */
604-
<Args extends any[]>(title: string, implementation: Implementation<Args, Context>, ...args: Args): void;
604+
<Args extends unknown[]>(title: string, implementation: Implementation<Args, Context>, ...args: Args): void;
605605

606606
/** Skip this test. */
607-
<Args extends any[]>(macro: Macro<Args, Context>, ...args: Args): void;
607+
<Args extends unknown[]>(macro: Macro<Args, Context>, ...args: Args): void;
608608
}
609609

610610
export interface TodoDeclaration {
611611
/** Declare a test that should be implemented later. */
612612
(title: string): void;
613613
}
614614

615-
export type MacroDeclarationOptions<Args extends any[], Context = unknown> = {
615+
export type MacroDeclarationOptions<Args extends unknown[], Context = unknown> = {
616616
exec: ImplementationFn<Args, Context>;
617617
title: TitleFn<Args>;
618618
};
619619

620620
export interface MacroDeclaration<Context = unknown> {
621621
/** Declare a reusable test implementation. */
622-
<Args extends any[]>(exec: ImplementationFn<Args, Context>): Macro<Args, Context>;
623-
<Args extends any[]>(declaration: MacroDeclarationOptions<Args, Context>): Macro<Args, Context>;
622+
<Args extends unknown[]>(exec: ImplementationFn<Args, Context>): Macro<Args, Context>;
623+
<Args extends unknown[]>(declaration: MacroDeclarationOptions<Args, Context>): Macro<Args, Context>;
624624
}
625625

626626
export interface MetaInterface {

test-d/macros.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -51,8 +51,8 @@ import test, {ExecutionContext} from '..';
5151
// Untyped arguments
5252
{
5353
const hasLength = test.macro((t, input, expected) => {
54-
expectType<any>(input);
55-
expectType<any>(expected);
54+
expectType<unknown>(input);
55+
expectType<unknown>(expected);
5656
});
5757

5858
test('bar has length 3', hasLength, 'bar', 3);

0 commit comments

Comments
 (0)