Skip to content

Commit

Permalink
types checked and updated
Browse files Browse the repository at this point in the history
  • Loading branch information
Samuel Furter committed Mar 26, 2019
1 parent 142f6e7 commit 73cfd74
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 12 deletions.
15 changes: 7 additions & 8 deletions packages/web3-eth/types/index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -54,11 +54,11 @@ export class Eth extends AbstractWeb3Module {

clearSubscriptions(): Promise<boolean>;

subscribe(
type: string,
options?: LogsOptions,
callback?: (error: Error, item: Log | Syncing | BlockHeader | string) => void
): Subscription<Log | BlockHeader | string | Syncing>;
subscribe(type: 'logs', options?: LogsOptions, callback?: (error: Error, log: Log) => void): Subscription<Log>;
subscribe(type: 'syncing', options?: null, callback?: (error: Error, result: Syncing) => void): Subscription<Syncing>;
subscribe(type: 'newBlockHeaders', options?: null, callback?: (error: Error, blockHeader: BlockHeader) => void): Subscription<BlockHeader>;
subscribe(type: 'pendingTransactions', options?: null, callback?: (error: Error, transactionHash: string) => void): Subscription<string>;
subscribe(type: 'pendingTransactions' | 'logs' | 'syncing' | 'newBlockHeaders', options?: any, callback?: (error: Error, result: any) => void): Subscription<Log | BlockHeader | Syncing | string>;

getProtocolVersion(callback?: (error: Error, protocolVersion: string) => void): Promise<string>;

Expand Down Expand Up @@ -192,9 +192,8 @@ export interface PastLogsOptions {
}

export interface LogsOptions {
fromBlock?: number | string,
toBlock?: number | string,
address?: string | string[]
fromBlock?: number | string;
address?: string | string[];
topics?: Array<string | string[]>
}

Expand Down
23 changes: 19 additions & 4 deletions packages/web3-eth/types/tests/eth.tests.ts
Original file line number Diff line number Diff line change
Expand Up @@ -45,13 +45,28 @@ eth.net;

eth.clearSubscriptions();

// $ExpectType Subscription<string | Log | BlockHeader | Syncing>
// $ExpectType Subscription<Log>
eth.subscribe('logs');

// $ExpectType Subscription<string | Log | BlockHeader | Syncing>
// $ExpectType Subscription<Log>
eth.subscribe('logs', {});
// $ExpectType Subscription<string | Log | BlockHeader | Syncing>
eth.subscribe('logs', {}, (error: Error, log: string | Log | Syncing | BlockHeader) => {});
// $ExpectType Subscription<Log>
eth.subscribe('logs', {}, (error: Error, log: Log) => {});

// $ExpectType Subscription<Syncing>
eth.subscribe('syncing');
// $ExpectType Subscription<Syncing>
eth.subscribe('syncing', null, (error: Error, result: Syncing) => {});

// $ExpectType Subscription<BlockHeader>
eth.subscribe('newBlockHeaders');
// $ExpectType Subscription<BlockHeader>
eth.subscribe('newBlockHeaders', null, (error: Error, blockHeader: BlockHeader) => {});

// $ExpectType Subscription<string>
eth.subscribe('pendingTransactions');
// $ExpectType Subscription<string>
eth.subscribe('pendingTransactions', null, (error: Error, transactionHash: string) => {});

// $ExpectType Providers
Eth.providers;
Expand Down

0 comments on commit 73cfd74

Please sign in to comment.