Skip to content

Commit

Permalink
Merge branch 'next' into next
Browse files Browse the repository at this point in the history
  • Loading branch information
ST-DDT authored Mar 4, 2024
2 parents 3601882 + c52ec8a commit a34f555
Show file tree
Hide file tree
Showing 8 changed files with 352 additions and 271 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -210,7 +210,7 @@ jobs:
run: pnpm vitest run --coverage

- name: Upload coverage to Codecov
uses: codecov/codecov-action@0cfda1dd0a4ad9efc75517f399d859cd1ea4ced1 # v4.0.2
uses: codecov/codecov-action@54bcd8715eee62d40e33596ef5e8f0f48dbbccab # v4.1.0
with:
token: ${{ secrets.CODECOV_TOKEN }}
fail_ci_if_error: true
38 changes: 38 additions & 0 deletions docs/guide/upgrading_v9/2563.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
### Stricter checking for function signature passed to `faker.helpers.multiple` method

The `faker.helpers.multiple` method takes a function reference as its first parameter. Previously you may have written code like this to generate multiple values.

```ts
faker.helpers.multiple(faker.date.past, { count: 2 });
```

However this code has a bug - `faker.helpers.multiple` passes the loop index as the second parameter to the method, which in this case would set the `refDate` of the `faker.date.past()` call to 0, making all dates before 1970.

Instead you should generally use a lambda function like

```ts
faker.helpers.multiple(() => faker.date.past(), { count: 2 });
```

to get the desired behavior. In v9.0, we use stricter type-checking in Typescript to detect when a function is called which is not compatible with `(v: unknown, index: number)` which can cause compile-time errors in places where previously there were potential runtime errors.

**Bad**

```ts
faker.helpers.multiple(faker.person.firstName, ...); //
// In Typescript, this is now a compile time error
// Argument of type '(sex?: "female" | "male" | undefined) => string'
// is not assignable to parameter of type '(v: unknown, index: number) => unknown'.
```

**Good**

```ts
faker.helpers.multiple(() => faker.person.firstName(), ...); //
```

The new types also allow for easier use-cases where the index is part of the generated data e.g. as id.

```ts
faker.helpers.multiple((_, index) => ({ id: index, ...}), ...); // [{id: 0, ...}, ...]
```
12 changes: 6 additions & 6 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -91,15 +91,15 @@
"@eslint-types/typescript-eslint": "~7.0.2",
"@eslint-types/unicorn": "~51.0.1",
"@types/markdown-it": "~13.0.7",
"@types/node": "~20.11.20",
"@types/node": "~20.11.24",
"@types/sanitize-html": "~2.11.0",
"@types/semver": "~7.5.8",
"@types/validator": "~13.11.9",
"@typescript-eslint/eslint-plugin": "~7.0.2",
"@typescript-eslint/parser": "~7.0.2",
"@typescript-eslint/eslint-plugin": "~7.1.0",
"@typescript-eslint/parser": "~7.1.0",
"@vitest/coverage-v8": "~1.3.1",
"@vitest/ui": "~1.3.1",
"@vueuse/core": "~10.8.0",
"@vueuse/core": "~10.9.0",
"conventional-changelog-cli": "~4.1.0",
"cypress": "~13.6.6",
"eslint": "~8.57.0",
Expand All @@ -121,13 +121,13 @@
"standard-version": "~9.5.0",
"tsup": "~8.0.2",
"tsx": "~4.7.1",
"typedoc": "~0.25.9",
"typedoc": "~0.25.10",
"typescript": "~5.3.3",
"validator": "~13.11.0",
"vite": "~5.1.4",
"vitepress": "1.0.0-rc.44",
"vitest": "~1.3.1",
"vue": "~3.4.20"
"vue": "~3.4.21"
},
"packageManager": "pnpm@8.15.4",
"engines": {
Expand Down
Loading

0 comments on commit a34f555

Please sign in to comment.