Backend: Bumping Typescript version to 4.4.2 (#748)

* Backend: Bumping Typescript version to 4.4.2

* Replacing any types with instanceOf checks.
This commit is contained in:
softsimon 2021-08-31 15:09:33 +03:00 committed by GitHub
parent 2e8ecc7277
commit ec12f21113
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
17 changed files with 73 additions and 63 deletions

4
.vscode/settings.json vendored Normal file
View File

@ -0,0 +1,4 @@
{
"editor.tabSize": 2,
"typescript.tsdk": "./backend/node_modules/typescript/lib"
}

4
backend/.vscode/settings.json vendored Normal file
View File

@ -0,0 +1,4 @@
{
"editor.tabSize": 2,
"typescript.tsdk": "../backend/node_modules/typescript/lib"
}

View File

@ -26,7 +26,7 @@
"@types/locutus": "^0.0.6",
"@types/ws": "^7.4.4",
"tslint": "^6.1.0",
"typescript": "^4.1.5"
"typescript": "4.4.2"
}
},
"node_modules/@babel/code-frame": {
@ -1473,10 +1473,11 @@
"integrity": "sha512-7uc1O8h1M1g0rArakJdf0uLRSSgFcYexrVoKo+bzJd32gd4gDy2L/Z+8/FjPnU9ydY3pEnVPtr9FyscYY60K1g=="
},
"node_modules/typescript": {
"version": "4.2.3",
"resolved": "https://registry.npmjs.org/typescript/-/typescript-4.2.3.tgz",
"integrity": "sha512-qOcYwxaByStAWrBf4x0fibwZvMRG+r4cQoTjbPtUlrWjBHbmCAww1i448U0GJ+3cNNEtebDteo/cHOR3xJ4wEw==",
"version": "4.4.2",
"resolved": "https://registry.npmjs.org/typescript/-/typescript-4.4.2.tgz",
"integrity": "sha512-gzP+t5W4hdy4c+68bfcv0t400HVJMMd2+H9B7gae1nQlBzCqvrXX+6GL/b3GAgyTH966pzrZ70/fRjwAtZksSQ==",
"dev": true,
"license": "Apache-2.0",
"bin": {
"tsc": "bin/tsc",
"tsserver": "bin/tsserver"
@ -2770,9 +2771,9 @@
"integrity": "sha512-7uc1O8h1M1g0rArakJdf0uLRSSgFcYexrVoKo+bzJd32gd4gDy2L/Z+8/FjPnU9ydY3pEnVPtr9FyscYY60K1g=="
},
"typescript": {
"version": "4.2.3",
"resolved": "https://registry.npmjs.org/typescript/-/typescript-4.2.3.tgz",
"integrity": "sha512-qOcYwxaByStAWrBf4x0fibwZvMRG+r4cQoTjbPtUlrWjBHbmCAww1i448U0GJ+3cNNEtebDteo/cHOR3xJ4wEw==",
"version": "4.4.2",
"resolved": "https://registry.npmjs.org/typescript/-/typescript-4.4.2.tgz",
"integrity": "sha512-gzP+t5W4hdy4c+68bfcv0t400HVJMMd2+H9B7gae1nQlBzCqvrXX+6GL/b3GAgyTH966pzrZ70/fRjwAtZksSQ==",
"dev": true
},
"unpipe": {
@ -2820,7 +2821,8 @@
"ws": {
"version": "7.4.6",
"resolved": "https://registry.npmjs.org/ws/-/ws-7.4.6.tgz",
"integrity": "sha512-YmhHDO4MzaDLB+M9ym/mDA5z0naX8j7SIlT8f8z+I0VtzsRbekxEutHSme7NPS2qE8StCYQNUnfWdXta/Yu85A=="
"integrity": "sha512-YmhHDO4MzaDLB+M9ym/mDA5z0naX8j7SIlT8f8z+I0VtzsRbekxEutHSme7NPS2qE8StCYQNUnfWdXta/Yu85A==",
"requires": {}
},
"yallist": {
"version": "4.0.0",

View File

@ -45,6 +45,6 @@
"@types/locutus": "^0.0.6",
"@types/ws": "^7.4.4",
"tslint": "^6.1.0",
"typescript": "^4.1.5"
"typescript": "4.4.2"
}
}

View File

@ -30,7 +30,7 @@ class BackendInfo {
try {
this.gitCommitHash = fs.readFileSync('../.git/refs/heads/master').toString().trim();
} catch (e) {
logger.err('Could not load git commit info: ' + e.message || e);
logger.err('Could not load git commit info: ' + (e instanceof Error ? e.message : e));
}
}
@ -39,7 +39,7 @@ class BackendInfo {
const packageJson = fs.readFileSync('package.json').toString();
this.version = JSON.parse(packageJson).version;
} catch (e) {
throw new Error(e);
throw new Error(e instanceof Error ? e.message : 'Error');
}
}
}

View File

@ -162,7 +162,7 @@ class Bisq {
this.buildIndex();
this.calculateStats();
} catch (e) {
logger.info('loadBisqDumpFile() error.' + e.message || e);
logger.info('loadBisqDumpFile() error.' + (e instanceof Error ? e.message : e));
}
}

View File

@ -102,7 +102,7 @@ class Bisq {
logger.debug('Bisq market data updated in ' + time + ' ms');
}
} catch (e) {
logger.err('loadBisqMarketDataDumpFile() error.' + e.message || e);
logger.err('loadBisqMarketDataDumpFile() error.' + (e instanceof Error ? e.message : e));
}
}

View File

@ -93,7 +93,7 @@ class BitcoindElectrsApi extends BitcoinApi implements AbstractBitcoinApi {
if (e === 'failed to get confirmed status') {
e = 'The number of transactions on this address exceeds the Electrum server limit';
}
throw new Error(e);
throw new Error(e instanceof Error ? e.message : 'Error');
}
}
@ -131,7 +131,7 @@ class BitcoindElectrsApi extends BitcoinApi implements AbstractBitcoinApi {
if (e === 'failed to get confirmed status') {
e = 'The number of transactions on this address exceeds the Electrum server limit';
}
throw new Error(e);
throw new Error(e instanceof Error ? e.message : 'Error');
}
}

View File

@ -89,7 +89,7 @@ class Blocks {
const tx = await transactionUtils.$getTransactionExtended(txIds[i]);
transactions.push(tx);
} catch (e) {
logger.debug('Error fetching block tx: ' + e.message || e);
logger.debug('Error fetching block tx: ' + (e instanceof Error ? e.message : e));
if (i === 0) {
throw new Error('Failed to fetch Coinbase transaction: ' + txIds[i]);
}

View File

@ -52,7 +52,7 @@ class DiskCache {
logger.debug('Mempool and blocks data saved to disk cache');
this.isWritingCache = false;
} catch (e) {
logger.warn('Error writing to cache file: ' + e.message || e);
logger.warn('Error writing to cache file: ' + (e instanceof Error ? e.message : e));
this.isWritingCache = false;
}
}

View File

@ -36,7 +36,7 @@ class FiatConversion {
this.ratesChangedCallback(this.conversionRates);
}
} catch (e) {
logger.err('Error updating fiat conversion rates: ' + e);
logger.err('Error updating fiat conversion rates: ' + (e instanceof Error ? e.message : e));
}
}
}

View File

@ -124,7 +124,7 @@ class Mempool {
}
newTransactions.push(transaction);
} catch (e) {
logger.debug('Error finding transaction in mempool: ' + e.message || e);
logger.debug('Error finding transaction in mempool: ' + (e instanceof Error ? e.message : e));
}
}

View File

@ -255,7 +255,7 @@ class Statistics {
connection.release();
return result.insertId;
} catch (e) {
logger.err('$create() error' + e.message || e);
logger.err('$create() error' + (e instanceof Error ? e.message : e));
}
}
@ -313,7 +313,7 @@ class Statistics {
return this.mapStatisticToOptimizedStatistic([rows[0]])[0];
}
} catch (e) {
logger.err('$list2H() error' + e.message || e);
logger.err('$list2H() error' + (e instanceof Error ? e.message : e));
}
}
@ -325,7 +325,7 @@ class Statistics {
connection.release();
return this.mapStatisticToOptimizedStatistic(rows);
} catch (e) {
logger.err('$list2H() error' + e.message || e);
logger.err('$list2H() error' + (e instanceof Error ? e.message : e));
return [];
}
}
@ -338,7 +338,7 @@ class Statistics {
connection.release();
return this.mapStatisticToOptimizedStatistic(rows);
} catch (e) {
logger.err('$list24h() error' + e.message || e);
logger.err('$list24h() error' + (e instanceof Error ? e.message : e));
return [];
}
}
@ -351,7 +351,7 @@ class Statistics {
connection.release();
return this.mapStatisticToOptimizedStatistic(rows);
} catch (e) {
logger.err('$list1W() error' + e);
logger.err('$list1W() error' + (e instanceof Error ? e.message : e));
return [];
}
}
@ -364,7 +364,7 @@ class Statistics {
connection.release();
return this.mapStatisticToOptimizedStatistic(rows);
} catch (e) {
logger.err('$list1M() error' + e);
logger.err('$list1M() error' + (e instanceof Error ? e.message : e));
return [];
}
}
@ -377,7 +377,7 @@ class Statistics {
connection.release();
return this.mapStatisticToOptimizedStatistic(rows);
} catch (e) {
logger.err('$list3M() error' + e);
logger.err('$list3M() error' + (e instanceof Error ? e.message : e));
return [];
}
}
@ -390,7 +390,7 @@ class Statistics {
connection.release();
return this.mapStatisticToOptimizedStatistic(rows);
} catch (e) {
logger.err('$list6M() error' + e);
logger.err('$list6M() error' + (e instanceof Error ? e.message : e));
return [];
}
}
@ -403,7 +403,7 @@ class Statistics {
connection.release();
return this.mapStatisticToOptimizedStatistic(rows);
} catch (e) {
logger.err('$list6M() error' + e);
logger.err('$list6M() error' + (e instanceof Error ? e.message : e));
return [];
}
}

View File

@ -61,7 +61,7 @@ class WebsocketHandler {
const fullTx = await transactionUtils.$getTransactionExtended(tx.txid, true);
response['tx'] = fullTx;
} catch (e) {
logger.debug('Error finding transaction: ' + e.message || e);
logger.debug('Error finding transaction: ' + (e instanceof Error ? e.message : e));
}
}
} else {
@ -69,7 +69,7 @@ class WebsocketHandler {
const fullTx = await transactionUtils.$getTransactionExtended(client['track-tx'], true);
response['tx'] = fullTx;
} catch (e) {
logger.debug('Error finding transaction. ' + e.message || e);
logger.debug('Error finding transaction. ' + (e instanceof Error ? e.message : e));
client['track-mempool-tx'] = parsedMessage['track-tx'];
}
}
@ -124,7 +124,7 @@ class WebsocketHandler {
client.send(JSON.stringify(response));
}
} catch (e) {
logger.debug('Error parsing websocket message: ' + e.message || e);
logger.debug('Error parsing websocket message: ' + (e instanceof Error ? e.message : e));
}
});
});
@ -252,7 +252,7 @@ class WebsocketHandler {
const fullTx = await transactionUtils.$getTransactionExtended(tx.txid, true);
response['tx'] = fullTx;
} catch (e) {
logger.debug('Error finding transaction in mempool: ' + e.message || e);
logger.debug('Error finding transaction in mempool: ' + (e instanceof Error ? e.message : e));
}
} else {
response['tx'] = tx;
@ -272,7 +272,7 @@ class WebsocketHandler {
const fullTx = await transactionUtils.$getTransactionExtended(tx.txid, true);
foundTransactions.push(fullTx);
} catch (e) {
logger.debug('Error finding transaction in mempool: ' + e.message || e);
logger.debug('Error finding transaction in mempool: ' + (e instanceof Error ? e.message : e));
}
} else {
foundTransactions.push(tx);
@ -286,7 +286,7 @@ class WebsocketHandler {
const fullTx = await transactionUtils.$getTransactionExtended(tx.txid, true);
foundTransactions.push(fullTx);
} catch (e) {
logger.debug('Error finding transaction in mempool: ' + e.message || e);
logger.debug('Error finding transaction in mempool: ' + (e instanceof Error ? e.message : e));
}
} else {
foundTransactions.push(tx);
@ -337,7 +337,7 @@ class WebsocketHandler {
const fullTx = await transactionUtils.$getTransactionExtended(rbfTransaction, true);
response['rbfTransaction'] = fullTx;
} catch (e) {
logger.debug('Error finding transaction in mempool: ' + e.message || e);
logger.debug('Error finding transaction in mempool: ' + (e instanceof Error ? e.message : e));
}
} else {
response['rbfTransaction'] = rbfTx;

View File

@ -20,7 +20,7 @@ export async function checkDbConnection() {
logger.info('Database connection established.');
connection.release();
} catch (e) {
logger.err('Could not connect to database: ' + e.message || e);
logger.err('Could not connect to database: ' + (e instanceof Error ? e.message : e));
process.exit(1);
}
}

View File

@ -111,7 +111,7 @@ class Server {
try {
await memPool.$updateMemPoolInfo();
} catch (e) {
const msg = `updateMempoolInfo: ${(e.message || e)}`;
const msg = `updateMempoolInfo: ${(e instanceof Error ? e.message : e)}`;
if (config.CORE_RPC_MINFEE.ENABLED) {
logger.warn(msg);
} else {
@ -123,7 +123,7 @@ class Server {
setTimeout(this.runMainUpdateLoop.bind(this), config.MEMPOOL.POLL_RATE_MS);
this.currentBackendRetryInterval = 5;
} catch (e) {
const loggerMsg = `runMainLoop error: ${(e.message || e)}. Retrying in ${this.currentBackendRetryInterval} sec.`;
const loggerMsg = `runMainLoop error: ${(e instanceof Error ? e.message : e)}. Retrying in ${this.currentBackendRetryInterval} sec.`;
if (this.currentBackendRetryInterval > 5) {
logger.warn(loggerMsg);
mempool.setOutOfSync();

View File

@ -55,7 +55,7 @@ class Routes {
const result = websocketHandler.getInitData();
res.json(result);
} catch (e) {
res.status(500).send(e.message);
res.status(500).send(e instanceof Error ? e.message : e);
}
}
@ -74,7 +74,7 @@ class Routes {
const result = mempoolBlocks.getMempoolBlocks();
res.json(result);
} catch (e) {
res.status(500).send(e.message);
res.status(500).send(e instanceof Error ? e.message : e);
}
}
@ -477,10 +477,10 @@ class Routes {
res.json(transaction);
} catch (e) {
let statusCode = 500;
if (e.message && e.message.indexOf('No such mempool or blockchain transaction') > -1) {
if (e instanceof Error && e instanceof Error && e.message && e.message.indexOf('No such mempool or blockchain transaction') > -1) {
statusCode = 404;
}
res.status(statusCode).send(e.message || e);
res.status(statusCode).send(e instanceof Error ? e.message : e);
}
}
@ -491,10 +491,10 @@ class Routes {
res.send(transaction.hex);
} catch (e) {
let statusCode = 500;
if (e.message && e.message.indexOf('No such mempool or blockchain transaction') > -1) {
if (e instanceof Error && e.message && e.message.indexOf('No such mempool or blockchain transaction') > -1) {
statusCode = 404;
}
res.status(statusCode).send(e.message || e);
res.status(statusCode).send(e instanceof Error ? e.message : e);
}
}
@ -504,10 +504,10 @@ class Routes {
res.json(transaction.status);
} catch (e) {
let statusCode = 500;
if (e.message && e.message.indexOf('No such mempool or blockchain transaction') > -1) {
if (e instanceof Error && e.message && e.message.indexOf('No such mempool or blockchain transaction') > -1) {
statusCode = 404;
}
res.status(statusCode).send(e.message || e);
res.status(statusCode).send(e instanceof Error ? e.message : e);
}
}
@ -516,7 +516,7 @@ class Routes {
const result = await bitcoinApi.$getBlock(req.params.hash);
res.json(result);
} catch (e) {
res.status(500).send(e.message || e);
res.status(500).send(e instanceof Error ? e.message : e);
}
}
@ -526,7 +526,7 @@ class Routes {
res.setHeader('content-type', 'text/plain');
res.send(blockHeader);
} catch (e) {
res.status(500).send(e.message || e);
res.status(500).send(e instanceof Error ? e.message : e);
}
}
@ -563,7 +563,7 @@ class Routes {
res.json(returnBlocks);
} catch (e) {
loadingIndicators.setProgress('blocks', 100);
res.status(500).send(e.message || e);
res.status(500).send(e instanceof Error ? e.message : e);
}
}
@ -582,13 +582,13 @@ class Routes {
transactions.push(transaction);
loadingIndicators.setProgress('blocktxs-' + req.params.hash, (i + 1) / endIndex * 100);
} catch (e) {
logger.debug('getBlockTransactions error: ' + e.message || e);
logger.debug('getBlockTransactions error: ' + (e instanceof Error ? e.message : e));
}
}
res.json(transactions);
} catch (e) {
loadingIndicators.setProgress('blocktxs-' + req.params.hash, 100);
res.status(500).send(e.message || e);
res.status(500).send(e instanceof Error ? e.message : e);
}
}
@ -597,7 +597,7 @@ class Routes {
const blockHash = await bitcoinApi.$getBlockHash(parseInt(req.params.height, 10));
res.send(blockHash);
} catch (e) {
res.status(500).send(e.message || e);
res.status(500).send(e instanceof Error ? e.message : e);
}
}
@ -611,10 +611,10 @@ class Routes {
const addressData = await bitcoinApi.$getAddress(req.params.address);
res.json(addressData);
} catch (e) {
if (e.message && e.message.indexOf('exceeds') > 0) {
return res.status(413).send(e.message);
if (e instanceof Error && e.message && e.message.indexOf('exceeds') > 0) {
return res.status(413).send(e instanceof Error ? e.message : e);
}
res.status(500).send(e.message || e);
res.status(500).send(e instanceof Error ? e.message : e);
}
}
@ -628,10 +628,10 @@ class Routes {
const transactions = await bitcoinApi.$getAddressTransactions(req.params.address, req.params.txId);
res.json(transactions);
} catch (e) {
if (e.message && e.message.indexOf('exceeds') > 0) {
return res.status(413).send(e.message);
if (e instanceof Error && e.message && e.message.indexOf('exceeds') > 0) {
return res.status(413).send(e instanceof Error ? e.message : e);
}
res.status(500).send(e.message || e);
res.status(500).send(e instanceof Error ? e.message : e);
}
}
@ -644,7 +644,7 @@ class Routes {
const blockHash = await bitcoinApi.$getAddressPrefix(req.params.prefix);
res.send(blockHash);
} catch (e) {
res.status(500).send(e.message || e);
res.status(500).send(e instanceof Error ? e.message : e);
}
}
@ -665,7 +665,7 @@ class Routes {
const rawMempool = await bitcoinApi.$getRawMempool();
res.send(rawMempool);
} catch (e) {
res.status(500).send(e.message || e);
res.status(500).send(e instanceof Error ? e.message : e);
}
}
@ -674,7 +674,7 @@ class Routes {
const result = await bitcoinApi.$getBlockHeightTip();
res.json(result);
} catch (e) {
res.status(500).send(e.message || e);
res.status(500).send(e instanceof Error ? e.message : e);
}
}
@ -683,7 +683,7 @@ class Routes {
const result = await bitcoinApi.$getTxIdsForBlock(req.params.hash);
res.json(result);
} catch (e) {
res.status(500).send(e.message || e);
res.status(500).send(e instanceof Error ? e.message : e);
}
}
@ -741,7 +741,7 @@ class Routes {
res.json(result);
} catch (e) {
res.status(500).send(e.message || e);
res.status(500).send(e instanceof Error ? e.message : e);
}
}
}