Skip to content

Commit

Permalink
Merge b3c0c03 into a7b5dea
Browse files Browse the repository at this point in the history
  • Loading branch information
Algoritm211 committed Sep 20, 2022
2 parents a7b5dea + b3c0c03 commit ada912e
Show file tree
Hide file tree
Showing 5 changed files with 10 additions and 7 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -555,6 +555,7 @@ Released with 1.0.0-beta.37 code base.
- Updated libraries using BN and the BN library (#5072)

### Added
- Generic types for `Contract`, now you can add types for your contract methods and events
- Exposing `web3.eth.Contract.setProvider()` as per public documentation (#4822) (#5001)
- Improve npm script commands for development purposes (#4848)

Expand Down
8 changes: 4 additions & 4 deletions packages/web3-eth-contract/types/index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,8 @@ import {Common, PromiEvent, provider, hardfork, chain, BlockNumber, PastLogsOpti
import {Accounts} from 'web3-eth-accounts';
import {AbiItem} from 'web3-utils';

// TODO: Add generic type!
export class Contract {
// Here you can provide generated types for methods and events from your contract
export class Contract<Methods = any, Events = any> {
constructor(
jsonInterface: AbiItem[],
address?: string,
Expand All @@ -50,7 +50,7 @@ export class Contract {

deploy(options: DeployOptions): ContractSendMethod;

methods: any;
methods: Methods;

once(
event: string,
Expand All @@ -62,7 +62,7 @@ export class Contract {
callback: (error: Error, event: EventData) => void
): void;

events: any;
events: Events;

getPastEvents(event: string): Promise<EventData[]>;
getPastEvents(
Expand Down
5 changes: 3 additions & 2 deletions packages/web3-eth/types/index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -65,11 +65,12 @@ export class Eth {
constructor(provider: provider);
constructor(provider: provider, net: net.Socket);

Contract: new (
// Here you can provide generated types for methods and events from your contract
Contract: new <Methods = any, Events = any>(
jsonInterface: AbiItem[] | AbiItem,
address?: string,
options?: ContractOptions
) => Contract;
) => Contract<Methods, Events>;
Iban: new (iban: string) => Iban;
personal: Personal;
accounts: Accounts;
Expand Down
2 changes: 1 addition & 1 deletion packages/web3-eth/types/tests/eth.tests.ts
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ eth.transactionBlockTimeout;
// $ExpectType boolean
eth.handleRevert;

// $ExpectType new (jsonInterface: AbiItem | AbiItem[], address?: string | undefined, options?: ContractOptions | undefined) => Contract
// $ExpectType new <Methods = any, Events = any>(jsonInterface: AbiItem | AbiItem[], address?: string | undefined, options?: ContractOptions | undefined) => Contract<Methods, Events>
eth.Contract;

// $ExpectType new (iban: string) => Iban
Expand Down
1 change: 1 addition & 0 deletions packages/web3-eth/types/tslint.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
{
"extends": "dtslint/dtslint.json",
"rules": {
"no-unnecessary-generics": false,
"semicolon": false,
"no-import-default-of-export-equals": false,
"file-name-casing": [true, "kebab-case"],
Expand Down

0 comments on commit ada912e

Please sign in to comment.