Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore: export AmountMath and deprecate but still export amountMath #3055

Merged
merged 2 commits into from
May 7, 2021
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 14 additions & 6 deletions packages/ERTP/src/amountMath.js
Original file line number Diff line number Diff line change
Expand Up @@ -170,7 +170,7 @@ const coerceLR = (h, leftAmount, rightAmount) => {
};

/** @type {AmountMath} */
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Doesn't the type's name need to change in order to not conflict with the export?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nope, I think the types are a different name space

const amountMath = {
const AmountMath = {
make: (brand, allegedValue) => {
if (looksLikeBrand(allegedValue)) {
// Swap to support deprecated reverse argument order
Expand All @@ -195,10 +195,10 @@ const amountMath = {
X`The brand in the allegedAmount ${allegedAmount} in 'coerce' didn't match the specified brand ${brand}.`,
);
// Will throw on inappropriate value
return amountMath.make(brand, allegedAmount.value);
return AmountMath.make(brand, allegedAmount.value);
},
// @ts-ignore TODO Why doesn't this type correctly?
getValue: (brand, amount) => amountMath.coerce(brand, amount).value,
getValue: (brand, amount) => AmountMath.coerce(brand, amount).value,
makeEmpty: (brand, mathKind = MathKind.NAT) => {
assert(
helpers[mathKind],
Expand All @@ -208,7 +208,7 @@ const amountMath = {
return noCoerceMake(helpers[mathKind].doMakeEmpty(), brand);
},
makeEmptyFromAmount: amount =>
amountMath.makeEmpty(amount.brand, getMathKind(amount)),
AmountMath.makeEmpty(amount.brand, getMathKind(amount)),
isEmpty: (amount, brand = undefined) => {
assertLooksLikeAmount(amount);
optionalBrandCheck(amount, brand);
Expand Down Expand Up @@ -243,6 +243,14 @@ const amountMath = {
);
},
};
harden(amountMath);
harden(AmountMath);

export { amountMath, MathKind, getMathKind };
/**
* Usage of lowercase `amountMath` is deprecated. Please import
* `AmountMath` instead.
*
* @deprecated
*/
const amountMath = AmountMath;

export { amountMath, AmountMath, MathKind, getMathKind };