js-stellar-sdk icon indicating copy to clipboard operation
js-stellar-sdk copied to clipboard

Effects typing fixes

Open eumemic opened this issue 9 months ago • 1 comments

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 avatar Apr 28 '24 09:04 eumemic

@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.

Shaptic avatar Jul 17 '24 18:07 Shaptic