Newtype (Tagged Type) in TypeScript
One of my favorite features in Haskell is newtype that allows you to wrap another type without any runtime overhead. Usually this is important when dealing with types that have the same underlying representation but should never be mixed together. Here is somewhat contrived example in Haskell:
newtype Dollars = Dollars { fromDollars :: Int }
newtype Euro = Euro { fromEuro :: Int }
processEuro :: Euro -> Euro
processEuro x = x
main = do
return $ processEuro $ Dollars 3 -- type error
Since most of my day-to-day work is done in TypeScript I’m quite often tempted to use a newtype, except I couldn’t, as there was no way to define a new unique type until TypeScript 2.7 where this feature was added to support ES2015+ Symbols.