Add ts-check for examples (#705)
* Add ts-check for examples * Typing cleanups, now shows properly * Bump * Cleanup checks * Bump keyring
This commit is contained in:
@@ -1,3 +1,4 @@
|
||||
// @ts-check
|
||||
// Required imports
|
||||
const { ApiPromise } = require('@polkadot/api');
|
||||
const { WsProvider } = require('@polkadot/rpc-provider');
|
||||
|
||||
@@ -1,3 +1,4 @@
|
||||
// @ts-check
|
||||
// Import the API
|
||||
const { ApiPromise } = require('@polkadot/api');
|
||||
|
||||
|
||||
@@ -1,3 +1,4 @@
|
||||
// @ts-check
|
||||
// Import the API
|
||||
const { ApiPromise } = require('@polkadot/api');
|
||||
|
||||
|
||||
@@ -1,3 +1,4 @@
|
||||
// @ts-check
|
||||
// Import the API
|
||||
const { ApiPromise } = require('@polkadot/api');
|
||||
|
||||
|
||||
@@ -1,3 +1,4 @@
|
||||
// @ts-check
|
||||
// Import the API
|
||||
const { ApiPromise } = require('@polkadot/api');
|
||||
|
||||
|
||||
@@ -1,3 +1,4 @@
|
||||
// @ts-check
|
||||
// Import the API, Keyring and some utility functions
|
||||
const { ApiPromise } = require('@polkadot/api');
|
||||
const { Keyring } = require('@polkadot/keyring');
|
||||
|
||||
@@ -1,3 +1,4 @@
|
||||
// @ts-check
|
||||
// Import the API
|
||||
const { ApiPromise } = require('@polkadot/api');
|
||||
|
||||
|
||||
@@ -1,3 +1,4 @@
|
||||
// @ts-check
|
||||
// Import the API & Provider and some utility functions
|
||||
const { ApiPromise } = require('@polkadot/api');
|
||||
|
||||
|
||||
@@ -1,3 +1,4 @@
|
||||
// @ts-check
|
||||
// Import the API & Provider and some utility functions
|
||||
const { ApiPromise } = require('@polkadot/api');
|
||||
const { WsProvider } = require('@polkadot/rpc-provider');
|
||||
|
||||
@@ -36,6 +36,6 @@
|
||||
"@polkadot/rpc-rx": "^0.43.8",
|
||||
"@polkadot/storage": "^0.43.8",
|
||||
"@polkadot/types": "^0.43.8",
|
||||
"@polkadot/util-crypto": "^0.34.17"
|
||||
"@polkadot/util-crypto": "^0.34.18"
|
||||
}
|
||||
}
|
||||
|
||||
@@ -524,7 +524,7 @@ export default abstract class ApiBase<CodecResult, SubscriptionResult> implement
|
||||
|
||||
result[sectionName] = Object.keys(derive[sectionName]).reduce((section, methodName) => {
|
||||
// FIXME The callback extraction we do way too much - de-dupe
|
||||
const method = (...args: Array<any>) => {
|
||||
const method = (...args: Array<any>): C | S => {
|
||||
let callback: CodecCallback | undefined;
|
||||
let params = args;
|
||||
|
||||
@@ -536,7 +536,7 @@ export default abstract class ApiBase<CodecResult, SubscriptionResult> implement
|
||||
return onCall((derive[sectionName] as any)[methodName], params, callback, !!callback);
|
||||
};
|
||||
|
||||
section[methodName] = method;
|
||||
section[methodName] = method as any; // CodecCallback or CodecArg form
|
||||
|
||||
return section;
|
||||
}, {} as DeriveSection<C, S>);
|
||||
|
||||
@@ -0,0 +1,42 @@
|
||||
// Copyright 2017-2019 @polkadot/api authors & contributors
|
||||
// This software may be modified and distributed under the terms
|
||||
// of the Apache-2.0 license. See the LICENSE file for details.
|
||||
|
||||
// Simple non-runnable checks to test type definitions in the editor itself
|
||||
|
||||
import { ApiPromise } from '@polkadot/api/index';
|
||||
import testKeyring from '@polkadot/keyring/testingPairs';
|
||||
import { Header, HeaderExtended } from '@polkadot/types/index';
|
||||
|
||||
export default async function test () {
|
||||
const api = await ApiPromise.create();
|
||||
const keyring = testKeyring();
|
||||
|
||||
const intentions = await api.query.staking.intentions();
|
||||
console.log('intentions:', intentions);
|
||||
|
||||
await api.query.staking.intentions((intentions) => {
|
||||
console.log('intentions:', intentions);
|
||||
});
|
||||
|
||||
await api.rpc.chain.subscribeNewHead((header: Header) => {
|
||||
console.log('current blockNumber:', header.blockNumber);
|
||||
});
|
||||
|
||||
await api.derive.chain.subscribeNewHead((header: HeaderExtended) => {
|
||||
console.log('current author:', header.author);
|
||||
});
|
||||
|
||||
const hash = await api.tx.balances
|
||||
.transfer(keyring.bob.address(), 12345)
|
||||
.signAndSend(keyring.alice);
|
||||
console.log('hash:', hash.toHex());
|
||||
|
||||
const unsub = await api.tx.balances
|
||||
.transfer(keyring.bob.address(), 12345)
|
||||
.signAndSend(keyring.alice, ({ type }) => {
|
||||
console.log('transfer status:', type);
|
||||
|
||||
unsub();
|
||||
});
|
||||
}
|
||||
@@ -84,7 +84,21 @@ export interface SubmittableExtrinsics<CodecResult, SubscriptionResult> {
|
||||
[index: string]: SubmittableModuleExtrinsics<CodecResult, SubscriptionResult>;
|
||||
}
|
||||
|
||||
export type DeriveMethod<CodecResult, SubscriptionResult> = (...params: Array<CodecArg>) => CodecResult | SubscriptionResult;
|
||||
export interface DeriveMethodBase<CodecResult, SubscriptionResult> {
|
||||
(...params: Array<CodecArg>): CodecResult;
|
||||
}
|
||||
|
||||
interface DeriveMethodPromise<CodecResult, SubscriptionResult> extends DeriveMethodBase<CodecResult, SubscriptionResult> {
|
||||
(callback: CodecCallback): SubscriptionResult;
|
||||
(arg0: CodecArg, callback: CodecCallback): SubscriptionResult;
|
||||
(arg0: CodecArg, arg1: CodecArg, callback: CodecCallback): SubscriptionResult;
|
||||
(arg0: CodecArg, arg1: CodecArg, arg2: CodecArg, callback: CodecCallback): SubscriptionResult;
|
||||
}
|
||||
|
||||
export type DeriveMethod<CodecResult, SubscriptionResult> =
|
||||
CodecResult extends Observable<any>
|
||||
? DeriveMethodBase<CodecResult, SubscriptionResult>
|
||||
: DeriveMethodPromise<CodecResult, SubscriptionResult>;
|
||||
|
||||
export interface DeriveSection<CodecResult, SubscriptionResult> {
|
||||
[index: string]: DeriveMethod<CodecResult, SubscriptionResult>;
|
||||
|
||||
@@ -33,6 +33,6 @@
|
||||
"@polkadot/jsonrpc": "^0.43.8",
|
||||
"@polkadot/rpc-provider": "^0.43.8",
|
||||
"@polkadot/types": "^0.43.8",
|
||||
"@polkadot/util": "^0.34.17"
|
||||
"@polkadot/util": "^0.34.18"
|
||||
}
|
||||
}
|
||||
|
||||
@@ -30,10 +30,10 @@
|
||||
"homepage": "https://github.com/polkadot-js/api/tree/master/packages/rpc-provider#readme",
|
||||
"dependencies": {
|
||||
"@babel/runtime": "^7.3.1",
|
||||
"@polkadot/keyring": "^0.34.17",
|
||||
"@polkadot/keyring": "^0.34.18",
|
||||
"@polkadot/storage": "^0.43.8",
|
||||
"@polkadot/util": "^0.34.17",
|
||||
"@polkadot/util-crypto": "^0.34.17",
|
||||
"@polkadot/util": "^0.34.18",
|
||||
"@polkadot/util-crypto": "^0.34.18",
|
||||
"@types/nock": "^9.3.1",
|
||||
"eventemitter3": "^3.1.0",
|
||||
"isomorphic-fetch": "^2.2.1",
|
||||
|
||||
@@ -12,6 +12,6 @@
|
||||
"dependencies": {
|
||||
"@babel/runtime": "^7.3.1",
|
||||
"@polkadot/types": "^0.43.8",
|
||||
"@polkadot/util": "^0.34.17"
|
||||
"@polkadot/util": "^0.34.18"
|
||||
}
|
||||
}
|
||||
|
||||
@@ -30,9 +30,9 @@
|
||||
"homepage": "https://github.com/polkadot-js/api/tree/master/packages/type-storage#readme",
|
||||
"dependencies": {
|
||||
"@babel/runtime": "^7.3.1",
|
||||
"@polkadot/keyring": "^0.34.17",
|
||||
"@polkadot/keyring": "^0.34.18",
|
||||
"@polkadot/types": "^0.43.8",
|
||||
"@polkadot/util": "^0.34.17",
|
||||
"@polkadot/util-crypto": "^0.34.17"
|
||||
"@polkadot/util": "^0.34.18",
|
||||
"@polkadot/util-crypto": "^0.34.18"
|
||||
}
|
||||
}
|
||||
|
||||
@@ -30,8 +30,8 @@
|
||||
"homepage": "https://github.com/polkadot-js/api/tree/master/packages/types#readme",
|
||||
"dependencies": {
|
||||
"@babel/runtime": "^7.3.1",
|
||||
"@polkadot/keyring": "^0.34.17",
|
||||
"@polkadot/util": "^0.34.17",
|
||||
"@polkadot/keyring": "^0.34.18",
|
||||
"@polkadot/util": "^0.34.18",
|
||||
"core-js": "^2.6.5"
|
||||
}
|
||||
}
|
||||
|
||||
@@ -6,7 +6,7 @@ import BN from 'bn.js';
|
||||
|
||||
export type CodecArg = Codec | BN | Boolean | String | Uint8Array | boolean | number | string | undefined | CodecArgArray | CodecArgObject;
|
||||
|
||||
export type CodecCallback <T extends Codec = Codec> = (result: T) => any;
|
||||
export type CodecCallback <T extends Codec = any> = (result: T) => any;
|
||||
|
||||
interface CodecArgObject {
|
||||
[index: string]: CodecArg;
|
||||
|
||||
@@ -1410,14 +1410,14 @@
|
||||
typedoc-plugin-no-inherit "^1.1.6"
|
||||
typescript "^3.3.3"
|
||||
|
||||
"@polkadot/keyring@^0.34.17":
|
||||
version "0.34.17"
|
||||
resolved "https://registry.yarnpkg.com/@polkadot/keyring/-/keyring-0.34.17.tgz#95bc75beec3eabbff3bb9d6939822efe4552f76c"
|
||||
integrity sha512-REW27eVZ+hG9icsekTMedl5twfaKCgeTxWyXomIS5arieyaMV0Y0Ty2QBmnYHXh1PdYUYaACsyGI3gBUu1d5Mw==
|
||||
"@polkadot/keyring@^0.34.18":
|
||||
version "0.34.18"
|
||||
resolved "https://registry.yarnpkg.com/@polkadot/keyring/-/keyring-0.34.18.tgz#a1d3fbb8d42d66b9b92933b2ca30ea19ad5d53aa"
|
||||
integrity sha512-mchfr4PG3fi3yTGfnMBo3F2sQmKVFBbLf//S/cdE4D9ki1lRGpZcUrFCAPbL49NOj60yZ28C+NjlEErucMEDNA==
|
||||
dependencies:
|
||||
"@babel/runtime" "^7.3.1"
|
||||
"@polkadot/util" "^0.34.17"
|
||||
"@polkadot/util-crypto" "^0.34.17"
|
||||
"@polkadot/util" "^0.34.18"
|
||||
"@polkadot/util-crypto" "^0.34.18"
|
||||
"@types/bs58" "^4.0.0"
|
||||
bs58 "^4.0.1"
|
||||
|
||||
@@ -1426,13 +1426,13 @@
|
||||
resolved "https://registry.yarnpkg.com/@polkadot/ts/-/ts-0.1.52.tgz#6fb09e494d244dad4b3a9ca581bfe13beec66565"
|
||||
integrity sha512-sij1O0x4CY51A394RYD4/aQwDPwIxIeTOpYI4AZgdF/vq5nvF14b4XFq9vAcSnblaIosf0sYKoz1f3dkN3QqLw==
|
||||
|
||||
"@polkadot/util-crypto@^0.34.17":
|
||||
version "0.34.17"
|
||||
resolved "https://registry.yarnpkg.com/@polkadot/util-crypto/-/util-crypto-0.34.17.tgz#509e21a2f716c42d04b6ef222faf811812df5aa7"
|
||||
integrity sha512-/hoz1+HqRiOaYPC+TET/KUDDBi661XiN8HZSz8dCZev3x/cqnCdGqbyy0BC8mHuST0VmN3n608E7HgrzXOQSnw==
|
||||
"@polkadot/util-crypto@^0.34.18":
|
||||
version "0.34.18"
|
||||
resolved "https://registry.yarnpkg.com/@polkadot/util-crypto/-/util-crypto-0.34.18.tgz#bba510325984324e1df9d9f540ffe21460369b02"
|
||||
integrity sha512-Tgc5uSotSpbK6mjqodTexdKxpdLFv10+JkoxYzFwt+vjAQ2bbAl3ElI8E7aN3Q5Fci6NydXsbX9EjcWSUK+/Uw==
|
||||
dependencies:
|
||||
"@babel/runtime" "^7.3.1"
|
||||
"@polkadot/util" "^0.34.17"
|
||||
"@polkadot/util" "^0.34.18"
|
||||
"@types/bip39" "^2.4.2"
|
||||
"@types/webassembly-js-api" "^0.0.2"
|
||||
"@types/xxhashjs" "^0.2.0"
|
||||
@@ -1442,10 +1442,10 @@
|
||||
tweetnacl "^1.0.1"
|
||||
xxhashjs "^0.2.2"
|
||||
|
||||
"@polkadot/util@^0.34.17":
|
||||
version "0.34.17"
|
||||
resolved "https://registry.yarnpkg.com/@polkadot/util/-/util-0.34.17.tgz#a60773694d91d1269f34a1c85660cf4f90ad76e6"
|
||||
integrity sha512-XbQXstHRBziILLHNT/1b2QESlnPprWiZkgHvESL4IjR3ToJzd+IpploH92EGED6MX/xTy+5WlCRbK4y8I/+mug==
|
||||
"@polkadot/util@^0.34.18":
|
||||
version "0.34.18"
|
||||
resolved "https://registry.yarnpkg.com/@polkadot/util/-/util-0.34.18.tgz#2147e2bf85e51163d6a4e2263fa659ee9794d7be"
|
||||
integrity sha512-3NEj1G4n2ZKAMJ6evduAB7jeBaXCwAEfeScA6WrK9zxZylCSzj2rgMFXcrb9O+5hoFp35QKHaqYF/NrkooRF+w==
|
||||
dependencies:
|
||||
"@babel/runtime" "^7.3.1"
|
||||
"@types/bn.js" "^4.11.4"
|
||||
|
||||
Reference in New Issue
Block a user