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

ledger stream onMessage: returns different type than expected #972

Open
acharb opened this issue May 20, 2024 · 1 comment
Open

ledger stream onMessage: returns different type than expected #972

acharb opened this issue May 20, 2024 · 1 comment
Assignees
Labels

Comments

@acharb
Copy link

acharb commented May 20, 2024

Describe the bug

When streaming ledgers with typescript the sdk says to expect CollectionPage, however the value received is just the ledger record

Makes it so have to type assert to LedgeRecord in order to use the value properly

What version are you on?

@stellar/stellar-sdk@^12.0.0-rc.2"

To Reproduce

import { Horizon } from "@stellar/stellar-sdk";

const streamTest = async () => {
  const horizon = new Horizon.Server("https://horizon-testnet.stellar.org");
  horizon
    .ledgers()
    .cursor("now")
    .limit(200)
    .stream({
      onmessage: async (
        msg: Horizon.ServerApi.CollectionPage<Horizon.ServerApi.LedgerRecord>,
      ) => {
        console.log(msg.closed_at); // throws error that .closed_at does not exist
      },
    });
};

streamTest();

In order to resolve have to do:

const streamTest = async () => {
  const horizon = new Horizon.Server("https://horizon-testnet.stellar.org");
  horizon
    .ledgers()
    .cursor("now")
    .limit(200)
    .stream({
      onmessage: async (msg: any) => {
        console.log((msg as Horizon.ServerApi.LedgerRecord).closed_at);
      },
    });
};

streamTest();

Trying to declare the param as LedgerRecord like so:

msg: Horizon.ServerApi.LedgerRecord

throws an error at compile time

Expected behavior

The onMessage value type should be LedgerRecord

@acharb acharb added the bug label May 20, 2024
@Shaptic Shaptic self-assigned this May 20, 2024
@Shaptic Shaptic moved this to To Do in Platform Scrum May 20, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
Status: To Do
Development

No branches or pull requests

3 participants
@Shaptic @acharb and others