faker
faker copied to clipboard
Faker.date generates ts error when passed into faker.unique
Pre-Checks
- [X] Follow our Code of Conduct.
- [X] Read the Contributing Guidelines.
- [X] Read the docs.
- [X] Check that there isn't already an issue that reports the same bug to avoid creating a duplicate.
- [X] Make sure this is a Faker issue and not related to a combination with another package.
- [X] Check that this is a concrete bug. For Q&A open a GitHub Discussion or join our Discord Chat Server.
- [X] The provided reproduction is a minimal reproducible example of the bug.
- [X] I am willing to provide a PR.
Describe the bug
Faker.date and it's children methods can't be used with unique method.
Generates the following TS error:
Argument of type '(years?: number, refDate?: string | number | Date) => Date' is not assignable to parameter of type '(...parameters: any[]) => RecordKey'.
Type 'Date' is not assignable to type 'RecordKey'.ts(2345)
Minimal reproduction code
const date = faker.unique(faker.date.past)
Additional Context
No response
Environment Info
System:
OS: macOS 12.5
CPU: (6) x64 Intel(R) Core(TM) i5-8500B CPU @ 3.00GHz
Memory: 1.48 GB / 32.00 GB
Shell: 5.8.1 - /bin/zsh
Binaries:
Node: 16.16.0 - ~/.asdf/installs/nodejs/16.16.0/bin/node
Yarn: 1.22.10 - /usr/local/bin/yarn
npm: 8.11.0 - ~/.asdf/plugins/nodejs/shims/npm
Browsers:
Chrome: 104.0.5112.79
Firefox: 103.0.2
Safari: 15.6
Which module system do you use?
- [ ] CJS
- [X] ESM
Used Package Manager
yarn
I can reproduce the error locally. I'm not sure whether the bug can be fixed in a non breaking way.
This requires breaking changes because the current api takes a Record to store the values.
We will change the unique store to be either a Set<T> or an T[] or add(T) => boolean.
Team decision: we will not work on this anymore
- #1785