nats-io / nats.ts

TypeScript Node.js client for NATS, the cloud native messaging system
https://www.nats.io
Apache License 2.0
178 stars 13 forks source link

Exporting NatsError #32

Closed leolanavo closed 5 years ago

leolanavo commented 5 years ago

Hi everyone,

It would be very awesome, if you exported the NatsError type, so you can properly type the MsgCallbacks.

This:

import { Msg } from 'ts-nats';

nats.subscribe('foo', (err: any, msg: Msg) => console.log(msg.subject);

Could become this:

import { Msg, NatsError } from 'ts-nats';

nats.subscribe('foo', (err: NatsError | null, msg: Msg) => console.log(msg.subject);

Way more beatiful, when you can type everything, and the code become more human friendly.

aricart commented 5 years ago

Looking into this - the main issue is the packaging dependencies. ts-nats is currently architected so that additional transports will plug into it. So some dependencies cannot leak through.

For now you can try

import {NatsError} from "ts-nats/lib/error";

If you have any suggestions let me know.

aricart commented 5 years ago

@leolanavo actually the solution is trivial - ts-nats just needs a simple export of the types that it imported and it does it. Putting a fix in.