Skip to content

Commit

Permalink
Added TypeScript tool support for functions with multiple outputs.
Browse files Browse the repository at this point in the history
  • Loading branch information
ricmoo committed Jul 27, 2019
1 parent b67b121 commit 6de4a5d
Showing 1 changed file with 11 additions and 1 deletion.
12 changes: 11 additions & 1 deletion packages/cli/src.ts/typescript.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@ function getType(param: ethers.utils.ParamType, flexible?: boolean): string {

if (param.type === "address" || param.type === "string") { return "string"; }

if (param.type === "bool") { return "boolean" }

if (param.type.substring(0, 5) === "bytes") {
if (flexible) {
return "string | ethers.utils.BytesLike";
Expand Down Expand Up @@ -76,7 +78,15 @@ export function generate(contract: ContractCode, bytecode?: string): string {
if (fragment.outputs.length === 1) {
output = "Promise<" + getType(fragment.outputs[0]) + ">";
} else {
throw new Error('not implemented yet');
// If all output parameters are names, we can specify the struct
if (fragment.outputs.filter((o) => (!!o.name)).length === fragment.outputs.length) {
output = "Promise<{ " + fragment.outputs.map((o, i) =>
((o.name || ("arg" + String(i)))+ ": " + getType(o))
).join(", ") + " }>";
} else {
// Otherwise, all we know is that it will be an Array
output = "Promise<{ Array<any> }>"
}
}
}

Expand Down

0 comments on commit 6de4a5d

Please sign in to comment.