@typechain/ethers-v5
Advanced tools
Comparing version 5.0.0 to 6.0.0
# @typechain/ethers-v5 | ||
## 6.0.0 | ||
### Major Changes | ||
- cd73777: Improve typings for events. Generate types for `queryFilter` for events. | ||
Note: This is a breaking change as it requires using TypeScript >= 4.0.0 (previously 3.9 was fine.) | ||
Example: | ||
```typescript | ||
const filter = contract.filters.Transfer() // TypedEventFilter<> | ||
const result = await contract.queryFilter(filter) // TypedEvent<> | ||
result[0].args.from // type support for named event parameters | ||
result[0].args[0] // type support by index | ||
contract.on(filter, (from, to, value, event) => { | ||
from // string | ||
to // string | ||
value // BigNumber | ||
event // TypedEvent<> | ||
}) | ||
``` | ||
## 5.0.0 | ||
### Major Changes | ||
- 0d4b293: Changed return type of functions from a object with number indexes, to an array merged with object containing named | ||
outputs. | ||
- 0d4b293: Changed return type of functions from a object with number indexes, to an array merged with object containing | ||
named outputs. | ||
Before, solidity function like this: | ||
``` | ||
function x() public pure returns (uint256) | ||
``` | ||
Generated such method signature: | ||
```typescript | ||
x(overrides?: CallOverrides): Promise<{0: BigNumber}>; | ||
``` | ||
New output is: | ||
```typescript | ||
x(overrides?: CallOverrides): Promise<[BigNumber]>; | ||
``` | ||
The difference is that now you can use standard array destructuring while working with output types. | ||
@@ -31,2 +57,3 @@ | ||
- db5baa5: Do not generate typings in contract type itself for reserved keywords that would collide with ethers internals | ||
- db5baa5: Do not generate typings in contract type itself for reserved keywords that would collide with ethers | ||
internals |
@@ -22,2 +22,3 @@ "use strict"; | ||
import { FunctionFragment, EventFragment, Result } from '@ethersproject/abi'; | ||
import { TypedEventFilter, TypedEvent, TypedListener } from './commons'; | ||
@@ -60,8 +61,22 @@ interface ${contract.name}Interface extends ethers.utils.Interface { | ||
on(event: EventFilter | string, listener: Listener): this; | ||
once(event: EventFilter | string, listener: Listener): this; | ||
addListener(eventName: EventFilter | string, listener: Listener): this; | ||
removeAllListeners(eventName: EventFilter | string): this; | ||
removeListener(eventName: any, listener: Listener): this; | ||
listeners<EventArgsArray extends Array<any>, EventArgsObject>(eventFilter?: TypedEventFilter<EventArgsArray, EventArgsObject>): Array<TypedListener<EventArgsArray, EventArgsObject>>; | ||
off<EventArgsArray extends Array<any>, EventArgsObject>(eventFilter: TypedEventFilter<EventArgsArray, EventArgsObject>, listener: TypedListener<EventArgsArray, EventArgsObject>): this; | ||
on<EventArgsArray extends Array<any>, EventArgsObject>(eventFilter: TypedEventFilter<EventArgsArray, EventArgsObject>, listener: TypedListener<EventArgsArray, EventArgsObject>): this; | ||
once<EventArgsArray extends Array<any>, EventArgsObject>(eventFilter: TypedEventFilter<EventArgsArray, EventArgsObject>, listener: TypedListener<EventArgsArray, EventArgsObject>): this; | ||
removeListener<EventArgsArray extends Array<any>, EventArgsObject>(eventFilter: TypedEventFilter<EventArgsArray, EventArgsObject>, listener: TypedListener<EventArgsArray, EventArgsObject>): this; | ||
removeAllListeners<EventArgsArray extends Array<any>, EventArgsObject>(eventFilter: TypedEventFilter<EventArgsArray, EventArgsObject>): this; | ||
listeners(eventName?: string): Array<Listener>; | ||
off(eventName: string, listener: Listener): this; | ||
on(eventName: string, listener: Listener): this; | ||
once(eventName: string, listener: Listener): this; | ||
removeListener(eventName: string, listener: Listener): this; | ||
removeAllListeners(eventName?: string): this; | ||
queryFilter<EventArgsArray extends Array<any>, EventArgsObject>( | ||
event: TypedEventFilter<EventArgsArray, EventArgsObject>, | ||
fromBlockOrBlockhash?: string | number | undefined, | ||
toBlock?: string | number | undefined | ||
): Promise<Array<TypedEvent<EventArgsArray & EventArgsObject>>>; | ||
interface: ${contract.name}Interface; | ||
@@ -241,3 +256,3 @@ | ||
return ` | ||
${event.name}(${generateEventTypes(event.inputs)}): EventFilter; | ||
${event.name}(${generateEventTypes(event.inputs)}): TypedEventFilter<${types_1.generateOutputTypes(true, event.inputs.map((input, i) => { var _a; return ({ name: (_a = input.name) !== null && _a !== void 0 ? _a : `arg${i.toString()}`, type: input.type }); })).replace(' &', ',')}>; | ||
`; | ||
@@ -244,0 +259,0 @@ } |
@@ -22,3 +22,4 @@ import { TContext, TFileDesc, TsGeneratorPlugin } from 'ts-generator'; | ||
afterRun(): TFileDesc[]; | ||
private genCommons; | ||
private genReExports; | ||
} |
@@ -88,2 +88,6 @@ "use strict"; | ||
{ | ||
path: path_1.join(this.outDirAbs, 'commons.ts'), | ||
contents: this.genCommons(), | ||
}, | ||
{ | ||
path: path_1.join(this.outDirAbs, 'index.ts'), | ||
@@ -95,2 +99,15 @@ contents: this.genReExports(), | ||
} | ||
genCommons() { | ||
return ` | ||
import { EventFilter, Event } from 'ethers' | ||
import { Result } from '@ethersproject/abi' | ||
export interface TypedEventFilter<EventArgsArray, EventArgsObject> extends EventFilter {} | ||
export interface TypedEvent<EventArgs extends Result> extends Event { | ||
args: EventArgs; | ||
} | ||
export type TypedListener<EventArgsArray extends Array<any>, EventArgsObject> = (...listenerArg: [...EventArgsArray, TypedEvent<EventArgsArray & EventArgsObject>]) => void;`; | ||
} | ||
genReExports() { | ||
@@ -97,0 +114,0 @@ const codegen = []; |
@@ -11,3 +11,3 @@ { | ||
], | ||
"version": "5.0.0", | ||
"version": "6.0.0", | ||
"license": "MIT", | ||
@@ -37,20 +37,10 @@ "repository": "https://github.com/ethereum-ts/Typechain", | ||
"typechain": "^4.0.0", | ||
"typescript": ">=3.8.0", | ||
"typescript": ">=4.0.0", | ||
"ethers": "^5.0.0" | ||
}, | ||
"devDependencies": { | ||
"@types/mocha": "^5.2.7", | ||
"@typescript-eslint/eslint-plugin": "^2.25.0", | ||
"@typescript-eslint/parser": "^2.12.0", | ||
"eslint": "^6.8.0", | ||
"eslint-config-typestrict": "^1.0.0", | ||
"eslint-plugin-no-only-tests": "^2.4.0", | ||
"eslint-plugin-sonarjs": "^0.5.0", | ||
"ganache-cli": "^6.9.1", | ||
"mocha": "^8.2.0", | ||
"test-utils": "1.0.0", | ||
"ts-node": "^8.5.4", | ||
"typechain": "*", | ||
"typescript": "3.9.0-beta" | ||
"typechain": "*" | ||
} | ||
} |
@@ -21,3 +21,3 @@ # Typechain target Ethers-v5 | ||
This package requires TypeScript >= 3.8. If you need support for earlier TS versions check out: 1.0 version of this | ||
This package requires TypeScript >= 4.0. If you need support for earlier TS versions check out: 1.0 version of this | ||
package. | ||
@@ -24,0 +24,0 @@ |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
New author
Supply chain riskA new npm collaborator published a version of the package for the first time. New collaborators are usually benign additions to a project, but do indicate a change to the security surface area of a package.
Found 1 instance in 1 package
51507
3
582
0