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

Effects typing fixes #947

Merged
merged 5 commits into from
Nov 13, 2024
Merged

Effects typing fixes #947

merged 5 commits into from
Nov 13, 2024

Conversation

eumemic
Copy link
Contributor

@eumemic eumemic commented Apr 28, 2024

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 eumemic changed the title Improve effect record typing to make use of discriminated union Allow discriminating effect types based on type field Apr 28, 2024
@eumemic eumemic changed the title Allow discriminating effect types based on type field Effects typing fixes Apr 28, 2024
Copy link
Contributor

@Shaptic Shaptic left a comment

Choose a reason for hiding this comment

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

Nice, I like it, Picasso 🤌 thank you!

@Shaptic
Copy link
Contributor

Shaptic commented Jul 17, 2024

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

Copy link
Contributor

@Shaptic Shaptic left a comment

Choose a reason for hiding this comment

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

Thanks for this!!

@Shaptic Shaptic merged commit e6957ff into stellar:master Nov 13, 2024
2 checks passed
BlaineHeffron pushed a commit to AhaLabs/js-stellar-sdk that referenced this pull request Nov 13, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants