Skip to content

Commit

Permalink
refactor(contract): address TS linter complaints
Browse files Browse the repository at this point in the history
add stronger typing to `nameFunction`
  • Loading branch information
chadoh committed Oct 7, 2020
1 parent eeb698a commit c3c69c3
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 4 deletions.
2 changes: 1 addition & 1 deletion lib/contract.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 3 additions & 3 deletions src/contract.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,16 +4,16 @@ import { getTransactionLastResult } from './providers';
import { PositionalArgsError, ArgumentTypeError } from './utils/errors';

// Makes `function.name` return given name
function nameFunction(name, body) {
function nameFunction(name: string, body: (args?: any[]) => {}) {
return {
[name](...args) {
[name](...args: any[]) {
return body(...args);
}
}[name];
}

const isUint8Array = (x: any) =>
x.byteLength !== undefined && x.byteLength === x.length;
x && x.byteLength !== undefined && x.byteLength === x.length;

const isObject = (x: any) =>
Object.prototype.toString.call(x) === '[object Object]';
Expand Down
4 changes: 4 additions & 0 deletions test/contract.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,10 @@ const contract = new Contract(account, null, {
test('throws PositionalArgsError if given too many arguments', () => {
return expect(contract[method]({}, 1, 0, 'oops')).rejects.toBeInstanceOf(PositionalArgsError);
});

test('allows args encoded as Uint8Array (for borsh)', async () => {
expect(await contract[method](new Uint8Array()));
});
});
});

Expand Down

0 comments on commit c3c69c3

Please sign in to comment.