Skip to content

Upgrade @faker-js/faker past 10.2, where sexType() can return 'generic' #1620

Closed

Description

@joshunrau

@faker-js/faker is held at ~10.2.0 in apps/api by the dependency update on the deps branch. The newest release eligible under the repo's 7-day minimumReleaseAge on 2026-10-04 was 10.6.0.

Why it was not upgraded

faker 10.3.0 adds Generic = "generic" to its Sex enum.

  • As a result, faker.person.sexType() is typed 'female' | 'male' | 'generic', even though it only returns 'generic' when passed { includeGeneric: true }.

  • The demo seeder upper-cases that value into a subject's sex:

    // apps/api/src/demo/demo.service.ts:109
    sex: toUpperCase(faker.person.sexType())
  • The value then goes to generateSubjectHash (line 114) and subjectsService.create (line 122). Both expect $Sex = z.enum(['MALE', 'FEMALE']) from packages/schemas/src/subject/subject.ts:9, so tsc fails with two TS2345 errors.

What is required

  • Narrow the value in demo.service.ts, for example with faker.helpers.arrayElement(['MALE', 'FEMALE'] as const).
  • Bump @faker-js/faker back to a caret range.
  • Seeded demo values can differ between faker versions, so check that no test asserts on specific seeded data.

Activity

  1. added
    Priority: Low
    Difficulty: Low
    Chore
    Area: API
    Good First Issue
    on Oct 5, 2026
  2. joshunrau commented on Oct 26, 2026

    @joshunrau
    CollaboratorAuthor

    Fixed by open PR #1660 (commit c0d58b9), not merged yet. main (d86740e) still pins "@faker-js/faker": "~10.2.0" at apps/api/package.json:27.

    Merging #1660 will not close this issue. Its body says Closes #1624, #1626, #1618, #1620, ..., but GitHub needs the keyword in front of each number, so #1624 is the only issue linked to the PR. Rewrite that line as Closes #1624, Closes #1626 and so on, or close this issue and the other 12 by hand after the merge.

    The fix in #1660

    It moves to ^10.6.0, which is still the latest release on npm. It seeds sex: faker.helpers.arrayElement($Sex.options) and drops the toUpperCase import, which nothing else uses. Use that rather than the literal ['MALE', 'FEMALE'] as const from the issue: the values come from $Sex, so the seeder can't drift from the schema. This is the only sexType() call in the repo.

    The new unit test pins the seeded sexes to $Sex.options. It also passes on the current code, because sexType() without options never returns 'generic'. What actually catches this break is tsc.

    Seeded data

    No test asserts on specific seeded values. demo.service.test.ts checks that the id is the hash of the seeded fields (:145-150), the custom-id numbering (:152-165) and the rating ranges (:186-200). It never checks a name, a date or a sex. The e2e specs create their own subjects through the start-session form, for example testing/src/specs/datahub.spec.ts:66.

    The change needs no new e2e spec. The global setup (testing/src/global/setup.spec.ts:15-22) seeds 10 subjects with 10 records each through DemoService.init (apps/api/src/setup/setup.service.ts:100-104), and both the chromium and firefox projects depend on it (testing/playwright.config.ts:26, :33).

    Landing

    #1660 conflicts with main. If it stalls, c0d58b9 cherry-picks onto main by itself without conflicts, pnpm-lock.yaml included. I checked this with a three-way merge of each file it touches. Run pnpm install afterwards to confirm the lockfile.

    The Dependabot PRs #1631 (~10.5.0) and #1579 (^10.5.0) also move faker past 10.3 without touching demo.service.ts. Merging either one would bring back the two TS2345 errors, so neither faker bump should land ahead of this fix.

    The Good First Issue label can come off, since the fix already exists.

    Triage note written with Claude Code. Code references point at main @ d86740e.

  3. added a commit that references this issue on Oct 26, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    Area: APIChoreDifficulty: LowGood First IssuePriority: Low

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions