From 2d1fe0437d84c9e5c7168c1c267a049ff75c19f9 Mon Sep 17 00:00:00 2001 From: Michael Bumann Date: Wed, 29 Jul 2020 22:30:06 +0200 Subject: [PATCH] Use Object.assign to prevent TypeScript error The use of the spread opertor causes issues in TypeScript 3.9.x To avoid this issue we use Object.assign to return on object with default values. TypeScript error: error TS2783: '' is specified more than once, so this usage will be overwritten. See Travis build with errors: https://travis-ci.org/github/joule-labs/joule-extension/builds/713053315 Related TypeScript issues: https://github.com/microsoft/TypeScript/issues/39671 https://github.com/microsoft/TypeScript/issues/38535 --- src/lnd/http/index.ts | 132 +++++++++++++++++++++++++----------------- 1 file changed, 79 insertions(+), 53 deletions(-) diff --git a/src/lnd/http/index.ts b/src/lnd/http/index.ts index 0b530988..61a34b9c 100644 --- a/src/lnd/http/index.ts +++ b/src/lnd/http/index.ts @@ -45,25 +45,29 @@ export class LndHttpClient implements T.LndAPI { channels: [], }).then((res) => { // Default attributes for channels - res.channels = res.channels.map((channel) => ({ - status: T.CHANNEL_STATUS.OPEN, - csv_delay: 0, - num_updates: 0, - private: false, - pending_htlcs: [], - remote_balance: '0', - commit_weight: '0', - capacity: '0', - local_balance: '0', - total_satoshis_received: '0', - active: false, - commit_fee: '0', - fee_per_kw: '0', - unsettled_balance: '0', - total_satoshis_sent: '0', - remote_node_pub: (channel as any).remote_pubkey, - ...channel, - })); + res.channels = res.channels.map((channel) => { + return Object.assign( + { + status: T.CHANNEL_STATUS.OPEN, + csv_delay: 0, + num_updates: 0, + private: false, + pending_htlcs: [], + remote_balance: '0', + commit_weight: '0', + capacity: '0', + local_balance: '0', + total_satoshis_received: '0', + active: false, + commit_fee: '0', + fee_per_kw: '0', + unsettled_balance: '0', + total_satoshis_sent: '0', + remote_node_pub: (channel as any).remote_pubkey, + }, + channel, + ); + }); return res; }); }; @@ -160,12 +164,16 @@ export class LndHttpClient implements T.LndAPI { return this.request('GET', '/v1/transactions', undefined, { transactions: [], }).then((res) => { - res.transactions = res.transactions.map((tx) => ({ - total_fees: '0', - amount: '0', - num_confirmations: 0, - ...tx, - })); + res.transactions = res.transactions.map((tx) => { + return Object.assign( + { + total_fees: '0', + amount: '0', + num_confirmations: 0, + }, + tx, + ); + }); return res; }); }; @@ -174,11 +182,15 @@ export class LndHttpClient implements T.LndAPI { return this.request('GET', '/v1/payments', undefined, { payments: [], }).then((res) => { - res.payments = res.payments.map((t) => ({ - fee: '0', - path: [], - ...t, - })); + res.payments = res.payments.map((t) => { + return Object.assign( + { + fee: '0', + path: [], + }, + t, + ); + }); return res; }); }; @@ -195,11 +207,15 @@ export class LndHttpClient implements T.LndAPI { }, ).then((res) => { // Default attributes for channels - res.invoices = res.invoices.map((invoice) => ({ - route_hints: [], - settled: false, - ...invoice, - })); + res.invoices = res.invoices.map((invoice) => { + return Object.assign( + { + route_hints: [], + settled: false, + }, + invoice, + ); + }); return res; }); }; @@ -243,11 +259,15 @@ export class LndHttpClient implements T.LndAPI { { routes: [] }, ).then((res) => { // Default attributes for channels - res.routes = res.routes.map((route) => ({ - total_fees: '0', - total_fees_msat: '0', - ...route, - })); + res.routes = res.routes.map((route) => { + return Object.assign( + { + total_fees: '0', + total_fees_msat: '0', + }, + route, + ); + }); return res; }); }; @@ -290,14 +310,18 @@ export class LndHttpClient implements T.LndAPI { peers: [], }).then((res) => { // Default attributes for peers - res.peers = res.peers.map((peer) => ({ - ping_time: '0', - sat_sent: '0', - sat_recv: '0', - bytes_sent: '0', - bytes_recv: '0', - ...peer, - })); + res.peers = res.peers.map((peer) => { + return Object.assign( + { + ping_time: '0', + sat_sent: '0', + sat_recv: '0', + bytes_sent: '0', + bytes_recv: '0', + }, + peer, + ); + }); return res; }); }; @@ -314,11 +338,13 @@ export class LndHttpClient implements T.LndAPI { '/v1/channels', params, ).then((res) => { - return { - output_index: '0', - funding_txid_str: txIdBytesToHex(res.funding_txid_bytes), - ...res, - }; + return Object.assign( + { + output_index: '0', + funding_txid_str: txIdBytesToHex(res.funding_txid_bytes), + }, + res, + ); }); };