Skip to content

Commit 51d725a

Browse files
authored
Merge pull request #1754 from dynst/any-removal-1
remove some any types
2 parents 447b457 + 7e56ff0 commit 51d725a

File tree

9 files changed

+16
-21
lines changed

9 files changed

+16
-21
lines changed

packages/amino/src/secp256k1hdwallet.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -202,7 +202,9 @@ export class Secp256k1HdWallet implements OfflineAminoSigner {
202202
): Promise<Secp256k1HdWallet> {
203203
const root = JSON.parse(serialization);
204204
if (!isNonNullObject(root)) throw new Error("Root document is not an object.");
205-
const untypedRoot: any = root;
205+
// This cast is safe because `root` comes from a valid JSON document and `root` is a non-null object.
206+
// I.e. it can only be a JSON object, not an aribitrary JS object.
207+
const untypedRoot: Record<string, any> = root;
206208
switch (untypedRoot.type) {
207209
case serializationTypeV1: {
208210
const decryptedBytes = await decrypt(

packages/amino/src/signdoc.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ import { Coin } from "./coins";
66

77
export interface AminoMsg {
88
readonly type: string;
9-
readonly value: any;
9+
readonly value: Record<string, any>;
1010
}
1111

1212
export interface StdFee {

packages/amino/src/stdtx.spec.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ describe("makeStdTx", () => {
5353
describe("isStdTx", () => {
5454
const validTx: StdTx = {
5555
memo: "memoe",
56-
msg: [{ type: "test", value: "Test Value" }],
56+
msg: [{ type: "test", value: { test: "Value" } }],
5757
fee: { amount: [{ denom: "ATOM", amount: "10" }], gas: "100000" },
5858
signatures: [{ signature: "signature", pub_key: { type: "type", value: "value" } }],
5959
};

packages/faucet-client/src/faucetclient.ts

Lines changed: 1 addition & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -22,15 +22,6 @@ export class FaucetClient {
2222
denom: denom,
2323
};
2424

25-
try {
26-
await fetch(this.baseUrl + "/credit", { method: "POST", body: JSON.stringify(body) });
27-
} catch (error: any) {
28-
if (error.response) {
29-
// append response body to error message
30-
throw new Error(`${error}; response body: ${JSON.stringify(error.response.data)}`);
31-
} else {
32-
throw error;
33-
}
34-
}
25+
await fetch(this.baseUrl + "/credit", { method: "POST", body: JSON.stringify(body) });
3526
}
3627
}

packages/faucet/src/api/webserver.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@ export class Webserver {
5858
}
5959

6060
// context.request.body is set by the bodyParser() plugin
61-
const requestBody = (context.request as any).body;
61+
const requestBody = context.request.body;
6262
const creditBody = RequestParser.parseCreditBody(requestBody);
6363
const { address, denom } = creditBody;
6464

packages/stargate/src/modules/gov/aminomessages.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ export interface AminoMsgSubmitProposal extends AminoMsg {
2828
*/
2929
readonly content: {
3030
readonly type: string;
31-
readonly value: any;
31+
readonly value: Record<string, any>;
3232
};
3333
readonly initial_deposit: readonly Coin[];
3434
/** Bech32 account address */

packages/stargate/src/stargateclient.ts

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -287,7 +287,8 @@ export class StargateClient {
287287
try {
288288
const account = await this.forceGetQueryClient().auth.account(searchAddress);
289289
return account ? this.accountParser(account) : null;
290-
} catch (error: any) {
290+
} catch (error) {
291+
assert(error instanceof Error);
291292
if (/rpc error: code = NotFound/i.test(error.toString())) {
292293
return null;
293294
}
@@ -369,7 +370,8 @@ export class StargateClient {
369370
delegatedAmount = (
370371
await this.forceGetQueryClient().staking.delegation(delegatorAddress, validatorAddress)
371372
).delegationResponse?.balance;
372-
} catch (e: any) {
373+
} catch (e) {
374+
assert(e instanceof Error);
373375
if (e.toString().includes("key not found")) {
374376
// ignore, `delegatedAmount` remains undefined
375377
} else {

packages/tendermint-rpc/src/rpcclients/http.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
function filterBadStatus(res: any): any {
1+
function filterBadStatus(res: Response): Response {
22
if (res.status >= 400) {
33
throw new Error(`Bad status on response: ${res.status}`);
44
}
@@ -28,5 +28,5 @@ export async function http(
2828
};
2929
return fetch(url, settings)
3030
.then(filterBadStatus)
31-
.then((res: any) => res.json());
31+
.then((res) => res.json());
3232
}

packages/tendermint-rpc/src/rpcclients/rpcclient.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ export interface SubscriptionEvent {
1212
readonly query: string;
1313
readonly data: {
1414
readonly type: string;
15-
readonly value: any;
15+
readonly value: Record<string, any>;
1616
};
1717
}
1818

@@ -26,7 +26,7 @@ export interface RpcStreamingClient extends RpcClient {
2626
}
2727

2828
export function instanceOfRpcStreamingClient(client: RpcClient): client is RpcStreamingClient {
29-
return typeof (client as any).listen === "function";
29+
return "listen" in client && typeof client.listen === "function";
3030
}
3131

3232
// Helpers for all RPC clients

0 commit comments

Comments
 (0)