From 8f7d68807bbcab403b7bb548ee55333d75eb43ce Mon Sep 17 00:00:00 2001 From: Doug Kent Date: Mon, 22 Oct 2018 11:36:43 -0400 Subject: [PATCH] [web3]: fix eth.getBalance return type (#29093) * fix eth.getBalance return type * fix callback return type too * docs are wrong, should be BigNumber * added overload and tests * correct optional params to be non-optional, add tests --- types/web3/eth/index.d.ts | 10 +++++++--- types/web3/web3-tests.ts | 5 +++++ 2 files changed, 12 insertions(+), 3 deletions(-) diff --git a/types/web3/eth/index.d.ts b/types/web3/eth/index.d.ts index d31c334598..1ed2a1094b 100644 --- a/types/web3/eth/index.d.ts +++ b/types/web3/eth/index.d.ts @@ -87,9 +87,13 @@ export default interface Eth { getAccounts(cb?: Callback): Promise; getBalance( address: string, - defaultBlock?: BlockType, - cb?: Callback - ): Promise; + defaultBlock?: BlockType + ): Promise; + getBalance( + address: string, + defaultBlock: BlockType, + cb: Callback + ): void; getBlock( number: BlockType, returnTransactionObjects?: boolean, diff --git a/types/web3/web3-tests.ts b/types/web3/web3-tests.ts index 6e9dc382da..ed30d4fce4 100644 --- a/types/web3/web3-tests.ts +++ b/types/web3/web3-tests.ts @@ -17,6 +17,11 @@ web3.eth.setProvider(myProvider); // web3.eth // -------------------------------------------------------------------------- const storage: Promise = web3.eth.getStorageAt(contractAddress, 0); +const balance1: Promise = web3.eth.getBalance(contractAddress); +const balance2: Promise = web3.eth.getBalance(contractAddress, "latest"); +const balance3: Promise = web3.eth.getBalance(contractAddress, 1); +web3.eth.getBalance(contractAddress, "latest", (error: Error, balance: BigNumber) => { }); +web3.eth.getBalance(contractAddress, 1, (error: Error, balance: BigNumber) => { }); const sendSignedTransactionTxReceipt0: PromiEvent = web3.eth.sendSignedTransaction("", (error: Error, txHash: string) => { });