Skip to content

Commit

Permalink
🏷️(vitest) No intermediate var to declare our types (#5766)
Browse files Browse the repository at this point in the history
**Description**

<!-- Please provide a short description and potentially linked issues
justifying the need for this PR -->

We used to rely on the typing of an intermediate variable to declare the
typings of `FastCheckItBuilder`. We dropped it to drop some unwanted
usages of the directive: `eslint-disable-next-line
@typescript-eslint/no-unused-vars`.

Related to #5282.

<!-- * Your PR is fixing a bug or regression? Check for existing issues
related to this bug and link them -->
<!-- * Your PR is adding a new feature? Make sure there is a related
issue or discussion attached to it -->

<!-- You can provide any additional context to help into understanding
what's this PR is attempting to solve: reproduction of a bug, code
snippets... -->

**Checklist** — _Don't delete this checklist and make sure you do the
following before opening the PR_

- [x] The name of my PR follows [gitmoji](https://gitmoji.dev/)
specification
- [x] My PR references one of several related issues (if any)
- [x] New features or breaking changes must come with an associated
Issue or Discussion
- [x] My PR does not add any new dependency without an associated Issue
or Discussion
- [x] My PR includes bumps details, please run `pnpm run bump` and flag
the impacts properly
- [x] My PR adds relevant tests and they would have failed without my PR
(when applicable)

<!-- More about contributing at
https://github.com/dubzzz/fast-check/blob/main/CONTRIBUTING.md -->

**Advanced**

<!-- How to fill the advanced section is detailed below! -->

- [ ] Category: ...
- [ ] Impacts: ...

<!-- [Category] Please use one of the categories below, it will help us
into better understanding the urgency of the PR -->
<!-- * ✨ Introduce new features -->
<!-- * 📝 Add or update documentation -->
<!-- * ✅ Add or update tests -->
<!-- * 🐛 Fix a bug -->
<!-- * 🏷️ Add or update types -->
<!-- * ⚡️ Improve performance -->
<!-- * _Other(s):_ ... -->

<!-- [Impacts] Please provide a comma separated list of the potential
impacts that might be introduced by this change -->
<!-- * Generated values: Can your change impact any of the existing
generators in terms of generated values, if so which ones? when? -->
<!-- * Shrink values: Can your change impact any of the existing
generators in terms of shrink values, if so which ones? when? -->
<!-- * Performance: Can it require some typings changes on user side?
Please give more details -->
<!-- * Typings: Is there a potential performance impact? In which cases?
-->
  • Loading branch information
dubzzz authored Mar 1, 2025
1 parent a867f4c commit 26d2012
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 11 deletions.
5 changes: 5 additions & 0 deletions .changeset/large-shoes-divide.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@fast-check/vitest": minor
---

🏷️(vitest) No intermediate var to declare our types
19 changes: 8 additions & 11 deletions packages/vitest/src/internals/TestBuilder.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,16 +20,6 @@ type TestPropRecord<Ts, TsParameters extends Ts = Ts> = (
params?: FcParameters<TsParameters>,
) => (testName: string, prop: PropRecord<Ts>, timeout?: number) => void;

/**
* prop has just been declared for typing reasons, ideally TestProp should be enough
* and should be used to replace `{ prop: typeof prop }` by `{ prop: TestProp<???> }`
*/
// eslint-disable-next-line @typescript-eslint/no-unused-vars
declare const prop: <Ts, TsParameters extends Ts = Ts>(
arbitraries: Ts extends [any] | any[] ? ArbitraryTuple<Ts> : ArbitraryRecord<Ts>,
params?: FcParameters<TsParameters>,
) => (testName: string, prop: Ts extends [any] | any[] ? Prop<Ts> : PropRecord<Ts>, timeout?: number) => void;

function adaptParametersForRecord<Ts>(
parameters: FcParameters<[Ts]>,
originalParamaters: FcParameters<Ts>,
Expand Down Expand Up @@ -124,7 +114,14 @@ function buildTestProp<Ts extends [any] | any[], TsParameters extends Ts = Ts>(
* Revamped {it,test} with added `.prop`
*/
export type FastCheckItBuilder<T> = T &
('each' extends keyof T ? T & { prop: typeof prop } : T) & {
('each' extends keyof T
? T & {
prop: <Ts, TsParameters extends Ts = Ts>(
arbitraries: Ts extends [any] | any[] ? ArbitraryTuple<Ts> : ArbitraryRecord<Ts>,
params?: FcParameters<TsParameters>,
) => (testName: string, prop: Ts extends [any] | any[] ? Prop<Ts> : PropRecord<Ts>, timeout?: number) => void;
}
: T) & {
[K in keyof Omit<T, 'each'>]: FastCheckItBuilder<T[K]>;
};

Expand Down

0 comments on commit 26d2012

Please sign in to comment.