js-stellar-sdk
js-stellar-sdk copied to clipboard
Effects typing fixes
Parameterize BaseEffectRecord
by effect type literals so that it's possible to discriminate based on the type
field. With this change code like the following type checks whereas before it would have had errors because the type of effect
wouldn't get appropriately narrowed in each case based on the value of effect.type
:
switch (effect.type) {
case "trade":
console.log("trade", effect.sold_amount, effect.bought_amount);
break;
case "liquidity_pool_trade":
console.log("liquidity_pool_trade", effect.liquidity_pool.reserves);
break;
// ...
}
Also added the type_i
field to the Trade
interface since it was missing, which was preventing even type_i
from working correctly to discriminate effect types.
@eumemic apologies for taking so long to review this - do you think you can sign the commits to get this merged? The repo blocks those commits otherwise.