js-stellar-sdk
js-stellar-sdk copied to clipboard
ledger stream onMessage: returns different type than expected
Describe the bug
When streaming ledgers with typescript the sdk says to expect CollectionPage<LedgerRecord>, 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