Adjust AnyBool & AnyString typings (#4850)

* Adjust AnyBool & AnyString typings

* Fix AnyString typing
This commit is contained in:
Jaco
2022-05-25 20:43:30 +03:00
committed by GitHub
parent 1fbfbac062
commit d41491e859
4 changed files with 10 additions and 7 deletions
+2 -3
View File
@@ -2,7 +2,7 @@
// SPDX-License-Identifier: Apache-2.0 // SPDX-License-Identifier: Apache-2.0
import type { HexString } from '@polkadot/util/types'; import type { HexString } from '@polkadot/util/types';
import type { Codec, Inspect, IU8a, Registry } from '../types'; import type { AnyBool, Codec, Inspect, IU8a, Registry } from '../types';
import { isU8a, u8aToHex } from '@polkadot/util'; import { isU8a, u8aToHex } from '@polkadot/util';
@@ -17,8 +17,7 @@ export class bool extends Boolean implements Codec {
public createdAtHash?: IU8a; public createdAtHash?: IU8a;
// eslint-disable-next-line @typescript-eslint/ban-types constructor (registry: Registry, value: bool | AnyBool | Uint8Array | number = false) {
constructor (registry: Registry, value: bool | Boolean | Uint8Array | boolean | number = false) {
super( super(
isU8a(value) isU8a(value)
? value[0] === 1 ? value[0] === 1
+5 -1
View File
@@ -10,7 +10,11 @@ export type AnyFunction = (...args: any[]) => any;
export type AnyNumber = BN | bigint | Uint8Array | number | string; export type AnyNumber = BN | bigint | Uint8Array | number | string;
export type AnyString = string | string; // eslint-disable-next-line @typescript-eslint/ban-types
export type AnyString = String | string;
// eslint-disable-next-line @typescript-eslint/ban-types
export type AnyBool = Boolean | boolean;
export type AnyTuple = Codec[]; export type AnyTuple = Codec[];
+2 -2
View File
@@ -11,8 +11,8 @@ import { ethereumEncode, isEthereumAddress } from '@polkadot/util-crypto';
function decodeAccountId (value: AnyU8a | AnyString): AnyU8a { function decodeAccountId (value: AnyU8a | AnyString): AnyU8a {
if (isU8a(value) || Array.isArray(value)) { if (isU8a(value) || Array.isArray(value)) {
return u8aToU8a(value); return u8aToU8a(value);
} else if (isHex(value) || isEthereumAddress(value)) { } else if (isHex(value) || isEthereumAddress(value.toString())) {
return hexToU8a(value); return hexToU8a(value.toString());
} else if (isString(value)) { } else if (isString(value)) {
return u8aToU8a(value); return u8aToU8a(value);
} }
+1 -1
View File
@@ -16,7 +16,7 @@ function decodeAccountId (value?: AnyU8a | AnyString): Uint8Array {
} else if (isHex(value)) { } else if (isHex(value)) {
return hexToU8a(value); return hexToU8a(value);
} else if (isString(value)) { } else if (isString(value)) {
return decodeAddress(value); return decodeAddress(value.toString());
} }
throw new Error(`Unknown type passed to AccountId constructor, found typeof ${typeof value}`); throw new Error(`Unknown type passed to AccountId constructor, found typeof ${typeof value}`);