From fec2b46a3e18f112b493800e13a4c74d1eaeb783 Mon Sep 17 00:00:00 2001 From: Andre Staltz Date: Tue, 26 Sep 2023 15:30:48 +0300 Subject: [PATCH] improve types for void callbacks --- lib/index.js | 13 ++++++------- 1 file changed, 6 insertions(+), 7 deletions(-) diff --git a/lib/index.js b/lib/index.js index 6d6e22e..3fc8d7f 100644 --- a/lib/index.js +++ b/lib/index.js @@ -62,11 +62,10 @@ const { decrypt } = require('./encryption') /** * @template T - * @typedef {(...args: [Error] | [null, T]) => void} CB - */ - -/** - * @typedef {(...args: [Error] | []) => void} CBVoid + * @typedef {T extends void ? + * (...args: [Error] | []) => void : + * (...args: [Error] | [null, T]) => void + * } CB */ class DBTangle extends MsgV3.Tangle { @@ -916,7 +915,7 @@ function initDB(peer, config) { /** * @param {string} msgID - * @param {CBVoid} cb + * @param {CB} cb */ function del(msgID, cb) { const rec = getRecord(msgID) @@ -931,7 +930,7 @@ function initDB(peer, config) { /** * @param {string} msgID - * @param {CBVoid} cb + * @param {CB} cb */ function erase(msgID, cb) { const rec = getRecord(msgID)