faker.date.betweens
should return a fixed-length tuple type rather than array of Date
#3407
Open
9 of 10 tasks
Labels
c: feature
Request for new feature
has workaround
Workaround provided or linked
m: date
Something is referring to the date module
p: 1-normal
Nothing urgent
s: awaiting more info
Additional information are requested
Pre-Checks
Describe the bug
faker.date.betweens
returns aDate[]
, which means:noUncheckedIndexedAccess
is set, all indexed values areDate | undefined
noUncheckedIndexAccess
is 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 providedcount
, defaulting to[Date, Date, Date]
to match the default count of 3.Minimal reproduction code
//
noUncheckedIndexAccess
is not set for this exampleconst 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
Which module system do you use?
Used Package Manager
npm
The text was updated successfully, but these errors were encountered: