gun
gun copied to clipboard
Typescript: Ack.err not typed correctly
if (ack.err) throw new Error(ack.err)
throws
Property 'err' does not exist on type 'GunMessagePut'. Property 'err' does not exist on type '{ ok: { '': 1; }; }'.ts(2339)
The callback would probably be better typed as
export type GunMessagePut =
| {
/** if there was an error during save */
err: string
}
& {
/** if there was a success message (none is required though) */
ok: { '': 1 }
}
export type GunCallbackPut = (ack: GunMessagePut) => void
unless it's an error on my end?
Have you tried this:
if('err' in ack) console.log(err)
else console.log(ack.ok)
I'm just asking because I didn't know about that trick on typescript Unions ;)