Sniberb
Sniberb3y ago

⛄ Snowberb ⛄ – 10-46 Jun 1

I'm trying to get the Max and the Min dates from an array of objects, but im having some problems. This is what I've done: startDate: new Date(Math.max(...bonuses.map((bonus) => new Date(bonus.fecha_evento)))) The problem is that typescript is telling me Argument of type 'Date' is not assignable to parameter of type 'number' How can I get the min and the max dates from an array of objects?
5 Replies
ScriptyChris
ScriptyChris3y ago
what is bonus.fecha_evento value exactly?
Sniberb
Sniberb3y ago
a string I just fixed it using getTime()
startDate: new Date(
Math.min(...bonuses.map((bonus) => new Date(bonus.fecha_evento).getTime()))
)
startDate: new Date(
Math.min(...bonuses.map((bonus) => new Date(bonus.fecha_evento).getTime()))
)
thank you for answering my question tho <3
ScriptyChris
ScriptyChris3y ago
hmm, i think it's weird TS yells about not assignable number parameter if you passed string there 🤔
Sniberb
Sniberb3y ago
yeah that's what I also thought
reactibot
reactibot3y ago
This thread hasn’t had any activity in 12 hours, so it’s now locked. Threads are closed automatically after 12 hours. If you have a followup question, you may want to reply to this thread so other members know they're related. https://discord.com/channels/102860784329052160/565213527673929729/981508938396758066