2 ms·
I just had a moment today. I'm developing a front-end thing in TypeScript. I'm messing around with dates across different data types (date string, Moment, a Neo
by mcv 3y ago
I just had a moment today. I'm developing a front-end thing in TypeScript. I'm messing around with dates across different data types (date string, Moment, a Neo4j-compatible date type, and Javascript's own Date type). Real fun, as you may understand. Struggling to convert a specific type straight to a js Date, I decide to just `new Date()` and add all the fields I need. `jsDate.setMonth(convert(otherDate.month))`. Red squiggly line appears underneath. I first realise it's a js Date, so I add a -1: `jsDate.setMonth(convert(otherDate.month)-1)`, and the red squiggly line disappear.
I feel a moment of horror. Type coercion. In front of my very eyes! I quickly added proper conversion everywhere.
I have no problem with dynamic types, but type coercion is the devil.