-
-
Notifications
You must be signed in to change notification settings - Fork 1k
Open
Labels
c: featureRequest for new featureRequest for new featurehas workaroundWorkaround provided or linkedWorkaround provided or linkedm: dateSomething is referring to the date moduleSomething is referring to the date modulep: 1-normalNothing urgentNothing urgent
Description
Pre-Checks
- Follow our Code of Conduct.
- Read the Contributing Guidelines.
- Read the docs.
- Check that there isn't already an issue that reports the same bug to avoid creating a duplicate.
- Make sure this is a Faker issue and not related to a combination with another package.
- Check that this is a concrete bug. For Q&A open a GitHub Discussion or join our Discord Chat Server.
- The provided reproduction is a minimal reproducible example of the bug.
- I am willing to provide a PR.
Describe the bug
faker.date.betweens returns a Date[], which means:
- if typescript option
noUncheckedIndexedAccessis set, all indexed values areDate | undefined - if
noUncheckedIndexAccessis not set, it is possible to index beyond the end of the array and have undefined at runtime, while the compile-type type isDate.
Ideally, faker.date.betweens should return a fixed-length tuple based on the provided count, defaulting to [Date, Date, Date] to match the default count of 3.
Minimal reproduction code
// noUncheckedIndexAccess is not set for this example
const fakeDates = faker.date.betweens({
from: "2020-01-01T00:00:00.000Z",
to: "2020-04-01T00:00:00.000Z",
count: 3,
});
let [a, b, c, d] = fakeDates;
// d is Date for type-checking, but undefined at runtime
const fakeDatesWithType = fakeDates as [Date, Date, Date];
// this is now a type error on h
let [e, f, g, h] = fakeDatesWithType;
Additional Context
No response
Environment Info
System:
OS: macOS 15.3.1
CPU: (10) arm64 Apple M1 Pro
Memory: 96.45 MB / 16.00 GB
Shell: 5.9 - /bin/zsh
Binaries:
Node: 22.14.0 - ~/.asdf/installs/nodejs/22.14.0/bin/node
npm: 10.9.2 - ~/.asdf/installs/nodejs/22.14.0/bin/npm
pnpm: 9.15.5 - ~/.asdf/shims/pnpm
Browsers:
Chrome: 133.0.6943.127
Safari: 18.3
npmPackages:
@faker-js/faker: ^9.0.3 => 9.5.0Which module system do you use?
- CJS
- ESM
Used Package Manager
npm
Metadata
Metadata
Assignees
Labels
c: featureRequest for new featureRequest for new featurehas workaroundWorkaround provided or linkedWorkaround provided or linkedm: dateSomething is referring to the date moduleSomething is referring to the date modulep: 1-normalNothing urgentNothing urgent