RadarTech / lnrpc

A Typescript gRPC client for LND with support for all LND sub-servers
MIT License
43 stars 13 forks source link

subscribeInvoice type incorrect, returns Readable not Promise #36

Closed wbobeirne closed 5 years ago

wbobeirne commented 5 years ago

This is the subscribeInvoice type currently provided:

LnRpc.subscribeInvoices(args?: InvoiceSubscription | undefined): Promise<Readable<Invoice>>

However the following code:

node.subscribeInvoices().then(stream => {
  stream.on('data', chunk => {
    console.log(chunk);
  });
});

results in the following error:

UnhandledPromiseRejectionWarning: TypeError: node_1.node.subscribeInvoices(...).then is not a function

Doing a quick log of the call:

const stream = node.subscribeInvoices();
console.log(stream);

Prints this, indicating it returns a readable, no promise wrap:

ClientReadableStream {
  _readableState:
    ReadableState {
      ...

I'm not sure if it's just the type that's wrong, or the non-promise behavior that's wrong, but I currently have to work around this by doing:

import { Invoice, Readable } from '@radar/lnrpc';

const stream = node.subscribeInvoices() as any as Readable<Invoice>;
stream.on('data', chunk => {
  console.log(chunk);
});
cavanmflynn commented 5 years ago

Ah, you're correct. Our usage of async/await hid the issue. Patching now.

cavanmflynn commented 5 years ago

Published in 0.6.0-beta.1