Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update to @faker-js/faker 6.3.1 or later #30143

Closed
MikeMcC399 opened this issue Aug 30, 2024 · 3 comments · Fixed by #30161
Closed

Update to @faker-js/faker 6.3.1 or later #30143

MikeMcC399 opened this issue Aug 30, 2024 · 3 comments · Fixed by #30161
Labels
process: dependencies Related to internal dependencies type: chore Work is required w/ no deliverable to end user

Comments

@MikeMcC399
Copy link
Contributor

What would you like?

  1. Update the npm module @faker-js/faker to minimum @faker-js/faker@6.3.1.
  2. Remove the use of the deprecated npm module @types/faker.

Why is this needed?

The repo https://github.com/Marak/Faker.js sourcing the npm module @types/faker was deleted and the module is de-facto now unsupported (see https://fakerjs.dev/about/announcements/2022-01-14.html#i-heard-something-happened-what-s-the-tldr).

As described in Migrating from Faker v5 to v6 in the TypeScript section

Faker now ships with its own types! Remove @types/faker from your package.json to avoid conflicts.

Other

Item Value
Deprecated npm module @types/faker
npm registry message This is a stub types definition. faker provides its own type definitions, so you do not need this installed.
Other message
GitHub repo https://github.com/Marak/Faker.js
Repo status Deleted
Replacement npm module https://www.npmjs.com/package/@faker-js/faker
Replacement repo https://github.com/faker-js/faker
Replacement documentation https://fakerjs.dev/
Migration docs https://v6.fakerjs.dev/migration-guide-v5/

Where used:

Directory Version
packages/app "@faker-js/faker": "5.5.3"
"@types/faker": "5.5.8"
packages/frontend-shared "@faker-js/faker": "5.5.3"
"@types/faker": "5.5.8"

Related PR

@jennifer-shehane jennifer-shehane added process: dependencies Related to internal dependencies type: chore Work is required w/ no deliverable to end user labels Aug 30, 2024
@MikeMcC399
Copy link
Contributor Author

MikeMcC399 commented Aug 30, 2024

After attempting an upgrade to @faker-js/faker@6.3.1 the following test fails:

$ yarn workspace @packages/frontend-shared check-ts
yarn workspace v1.22.22
yarn run v1.22.22
$ vue-tsc --noEmit
script/testStubSpecs.ts:140:7 - error TS2322: Type 'keyof T' is not assignable to type 'TemplateExecutor'.
  Type 'string | number | symbol' is not assignable to type 'TemplateExecutor'.
    Type 'string' is not assignable to type 'TemplateExecutor'.

140       template: faker.random.objectElement<TemplateExecutor>(nameTemplates),
          ~~~~~~~~

script/testStubSpecs.ts:140:44 - error TS2558: Expected 2 type arguments, but got 1.

140       template: faker.random.objectElement<TemplateExecutor>(nameTemplates),
                                               ~~~~~~~~~~~~~~~~


Found 2 errors in the same file, starting at: script/testStubSpecs.ts:140

error Command failed with exit code 2.
info Visit https://yarnpkg.com/en/docs/cli/run for documentation about this command.
error Command failed.
Exit code: 2

The code is here:

export const randomComponents = <T extends 'Spec' | 'FileParts'>(n = 200, baseTypename: T) => {
return faker.random.arrayElements(allRandomComponents, n).map((d: ReturnType<typeof combineProperties>) => {
const componentName = componentNameGenerator({
overrides: d,
template: faker.random.objectElement<TemplateExecutor>(nameTemplates),
})

Unfortunately I don't have the coding skills to know how to fix this. I'm just sharing what I discovered in my failed attempt to upgrade.

@raygdev
Copy link
Contributor

raygdev commented Aug 31, 2024

@MikeMcC399
If you create a type

type NameTemplate = {
  readonly [key: string]: TemplateExecutor
}

Then pass it as the generic arguments to objectElement

{
  // ...
  // this will tell TS the return type of "objectElement" is a TemplateExecutor
  // which is what's expected.
  template: faker.random.objectElement<NameTemplate, keyof NameTemplate>(nameTemplates)
}

Alternatively you could use the objectValue method from the helpers module (also where the arrayElements method moved to) :

 {
   // ...
   template: faker.helpers.objectValue<NameTemplate>(nameTemplates),
 }

This should make typescript happy.

run the check-ts again after the changes, it should be good.

@MikeMcC399
Copy link
Contributor Author

@raygdev

Many thanks for your solution suggestions! Please feel free to submit a PR to resolve this issue. My goal was to prepare as much as I could for the list of deprecated dependencies, not to necessarily resolve all of them myself. You have better skills than I do for this issue, so it would make sense for you to take the lead.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
process: dependencies Related to internal dependencies type: chore Work is required w/ no deliverable to end user
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants