Closed MikeMcC399 closed 2 weeks ago
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:
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.
@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.
@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.
What would you like?
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
Other
Where used:
"@faker-js/faker": "5.5.3"
"@types/faker": "5.5.8"
"@faker-js/faker": "5.5.3"
"@types/faker": "5.5.8"
latest
is currently8.4.1
Related PR