Skip to content

Commit

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

clearSubscriptions(): Promise<boolean>;

subscribe(type: 'logs', options?: Logs, callback?: (error: Error, log: Log) => void): Subscription<Log>;
subscribe(type: 'syncing', options?: null, callback?: (error: Error, result: any) => void): Subscription<any>;
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: string,
options?: LogsOptions,
callback?: (error: Error, item: Log | Syncing | BlockHeader | string) => void
): Subscription<Log | BlockHeader | string | Syncing>;

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

Expand Down Expand Up @@ -186,12 +187,13 @@ export interface Block extends BlockHeader {
export interface PastLogsOptions {
fromBlock?: number | string;
toBlock?: number | string;
address: string | string[];
address?: string | string[];
topics?: Array<string | string[]>;
}

export interface Logs {
fromBlock?: number
export interface LogsOptions {
fromBlock?: number | string,
toBlock?: number | string,
address?: string | string[]
topics?: Array<string | string[]>
}
Expand Down
23 changes: 4 additions & 19 deletions packages/web3-eth/types/tests/eth.tests.ts
Original file line number Diff line number Diff line change
Expand Up @@ -45,28 +45,13 @@ eth.net;

eth.clearSubscriptions();

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

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

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

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

// $ExpectType Providers
Eth.providers;
Expand Down

0 comments on commit 142f6e7

Please sign in to comment.