money-ts icon indicating copy to clipboard operation
money-ts copied to clipboard

ExchangeRate types don't match implementation

Open felixSchl opened this issue 3 years ago • 0 comments

The type of exchange is currently

export const exchange = <S extends string, D extends string>(er: ExchangeRate<S, D>) => (d: Dense<S>): Dense<D> => {
  return unsafeCoerce(d.mul(unwrap(er)))
}

The problem is that Dense<D> also carries runtime information for D. In the implementation above this information is not adapter, so you end up with a value thinking it's Dense<D> when at runtime it's still Dense<S>. You can see this in effect when trying to round the resulting Dense<D> - it will try to look up the target unit under source format's scale table.

felixSchl avatar Oct 11 '21 20:10 felixSchl