RadarTech / lnrpc

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

Types don't present useful errors #23

Closed wbobeirne closed 5 years ago

wbobeirne commented 5 years ago

Hey all, loving what you're providing to the TypeScript + Lightning ecosystem, hope I can help out going forward. Just started using lnrpc, and I'm finding the type errors to be really hard to grok. Take for instance this line of code that I'm converting over from using ln-service which has a slightly different api and nomenclature for arguments:

lnRpc.addInvoice({
  description: 'My item',
  tokens: '10000',
  expires_at: expires.toISOString(),
})

This results in the following error:

Argument of type '{ description: string; tokens: number; expires_at: string; }' is not assignable to parameter of type 'Partial<AsObject>'.
  Object literal may only specify known properties, and 'description' does not exist in type 'Partial<AsObject>'.

It looks like due to the AsObject wrapping that the types have, you don't really get useful information out of the errors. It's only by drilling down into the types that I can find the definition for AsObject. Not sure how the types are generated, and if there's a better way to surface them, but it'd definitely improve the developer experience!

cavanmflynn commented 5 years ago

I agree, the type errors that currently surface are not helpful.

We are planning to stop consuming the generated types directly and use them for diff comparisons between LND versions only. This will allow us to write the actual lnrpc types in a flatter, cleaner, and more developer-friendly format.

I'll make this update in the next week. Thanks!

cavanmflynn commented 5 years ago

We've removed the direct usage of generated types in release 0.5.2-beta.3.