PR1: A good first step would be providing the types of such events exported standalone, for example
// definition
export interface LedgerEvent {
ledgerVersion: number;
// ...
}
// usage
import { RippleAPI, LedgerEvent } from "ripple-lib";
const api = new RippleAPI({ /* ... */ });
api.on('ledger', (ledger) => console.log((ledger as LedgerEvent).ledgerVersion));
PR2: After the types are defined TypeScript function overloads could be used to type the EventEmitter api in a way that would only allow specified event names and automatically get the type of the event callback similar to how the request method is typed already.
As the project supports TypeScript, it would be nice to have typed stream events.
For example I could not find the type (interface) of LedgerEvent in the code (neither exported nor internal). However, there are JSON schemas for the events: https://github.com/ripple/ripple-lib/blob/d82703f41b41153f647084a50013bad35f301f9c/src/common/schemas/output/ledger-event.json
PR1: A good first step would be providing the types of such events exported standalone, for example
PR2: After the types are defined TypeScript function overloads could be used to type the EventEmitter api in a way that would only allow specified event names and automatically get the type of the event callback similar to how the
request
method is typed already.