Re:You may not need Moment.js
by jestar_jokin on Sunday September 19, 2021 @10:37PM
(#28589897)
Libs provide something out of the box to do this, e.g. `ts-essentials` provides `Opaque`, so you just write `type DateString = Opaque<string, 'DateString'>`
[ Parent
| on HN ]
Re:You may not need Moment.js
by eyelidlessness on Monday September 20, 2021 @04:02PM
(#28598231)
Their version is essentially my Symbol approach, but only in the type system. This does work, but it has the disadvantage that the type and runtime don't match. It’s certainly better than most Brand types which tend to rely on strings, but I prefer not to expose public properties which don’t exist.
The class/private approach has the advantage of hiding the extra property from everything except the type checker.