From bd50e48242e62988be02b07ffd35361b4a66cf5b Mon Sep 17 00:00:00 2001 From: ehsan shariati Date: Sun, 20 Aug 2023 23:29:00 -0400 Subject: [PATCH] corrected errors MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit tsconfig.json:26:5 - error TS5023: Unknown compiler option 'verbatimModuleSyntax'. 26 "verbatimModuleSyntax": true ~~~~~~~~~~~~~~~~~~~~~~ src/protocols/chain-api.ts:82:30 - error TS2722: Cannot invoke an object which is possibly 'undefined'. 82 const lastPoolId = await api.query.pool.lastPoolId(); ~~~~~~~~~~~~~~~~~~~~~~~~~ src/protocols/chain-api.ts:88:30 - error TS2722: Cannot invoke an object which is possibly 'undefined'. 88 const poolInfo = await api.query.pool.pools(i).catch((err) => { ~~~~~~~~~~~~~~~~~~~~ src/protocols/chain-api.ts:119:31 - error TS18048: 'api.query.pool' is possibly 'undefined'. 119 const poolRequest = await api.query.pool.poolRequests(poolId, accountId); ~~~~~~~~~~~~~~ src/protocols/chain-api.ts:119:31 - error TS2722: Cannot invoke an object which is possibly 'undefined'. 119 const poolRequest = await api.query.pool.poolRequests(poolId, accountId); ~~~~~~~~~~~~~~~~~~~~~~~~~~~ src/protocols/fula.ts:29:15 - error TS2339: Property 'initFula' does not exist on type 'FulaNativeModule'. 29 return Fula.initFula( ~~~~~~~~ Found 6 errors in 3 files. Errors Files 1 tsconfig.json:26 4 src/protocols/chain-api.ts:82 1 src/protocols/fula.ts:29 ✖ Failed to build definition files. --- src/interfaces/fulaNativeModule.ts | 2 +- src/protocols/chain-api.ts | 8 ++++++++ 2 files changed, 9 insertions(+), 1 deletion(-) diff --git a/src/interfaces/fulaNativeModule.ts b/src/interfaces/fulaNativeModule.ts index a4495d1..42ac499 100644 --- a/src/interfaces/fulaNativeModule.ts +++ b/src/interfaces/fulaNativeModule.ts @@ -1,7 +1,7 @@ import { NativeModules, Platform } from 'react-native'; interface FulaNativeModule { - init: ( + initFula: ( identity: string, //Private key of did identity storePath: string, //You can leave empty bloxAddr: string, //Blox multiadddr needs to be manually entered now diff --git a/src/protocols/chain-api.ts b/src/protocols/chain-api.ts index c94ffab..7979fb3 100644 --- a/src/protocols/chain-api.ts +++ b/src/protocols/chain-api.ts @@ -74,6 +74,10 @@ export const listPools = async ( if (api === undefined) { api = await init(); } + // Type guard to assure TypeScript that api is not undefined + if (!api || !api.query || !api.query.pool || !api.query.pool.lastPoolId || !api.query.pool.pools) { + throw new Error('Failed to initialize api or api.query.pool'); + } const pools: BType.PoolListResponse = { pools: [] }; const lastPoolId = await api.query.pool.lastPoolId(); let finalReturnedId: number = Number(lastPoolId.toHuman()); @@ -111,6 +115,10 @@ export const checkJoinRequest = async ( if (api === undefined) { api = await init(); } + // Type guard to assure TypeScript that api is not undefined + if (!api || !api.query || !api.query.pool || !api.query.pool.poolRequests) { + throw new Error('Failed to initialize api or api.query.pool'); + } const poolRequest = await api.query.pool.poolRequests(poolId, accountId);