Bump dev (w/ ts-eslint updates) (#5691)
This commit is contained in:
@@ -40,7 +40,13 @@ function getTypeClassMap (value: TypeDef): Record<string, string> {
|
||||
const map: Record<string, string> = {};
|
||||
|
||||
for (let i = 0, count = subs.length; i < count; i++) {
|
||||
map[subs[i].name as string] = getTypeDefType(subs[i]);
|
||||
const sub = subs[i];
|
||||
|
||||
if (!sub.name) {
|
||||
throw new Error(`No name found in definition ${stringify(sub)}`);
|
||||
}
|
||||
|
||||
map[sub.name] = getTypeDefType(sub);
|
||||
}
|
||||
|
||||
return map;
|
||||
@@ -88,7 +94,11 @@ const infoMapping: Record<TypeDefInfo, (registry: Registry, value: TypeDef) => C
|
||||
return Enum.with(
|
||||
subs.every(({ type }) => type === 'Null')
|
||||
? subs.reduce<Record<string, number>>((out, { index, name }, count) => {
|
||||
out[name as string] = index || count;
|
||||
if (!name) {
|
||||
throw new Error('No name found in sub definition');
|
||||
}
|
||||
|
||||
out[name] = index || count;
|
||||
|
||||
return out;
|
||||
}, {})
|
||||
@@ -152,7 +162,11 @@ const infoMapping: Record<TypeDefInfo, (registry: Registry, value: TypeDef) => C
|
||||
[TypeDefInfo.Set]: (_registry: Registry, value: TypeDef): CodecClass<Codec> =>
|
||||
CodecSet.with(
|
||||
getSubDefArray(value).reduce<Record<string, number>>((result, { index, name }) => {
|
||||
result[name as string] = index as number;
|
||||
if (!name || !isNumber(index)) {
|
||||
throw new Error('No name found in sub definition');
|
||||
}
|
||||
|
||||
result[name] = index;
|
||||
|
||||
return result;
|
||||
}, {}),
|
||||
@@ -225,7 +239,7 @@ export function constructTypeClass<T extends Codec = Codec> (registry: Registry,
|
||||
|
||||
// Returns the type Class for construction
|
||||
export function getTypeClass<T extends Codec = Codec> (registry: Registry, typeDef: TypeDef): CodecClass<T> {
|
||||
return registry.getUnsafe(typeDef.type, false, typeDef) as CodecClass<T>;
|
||||
return registry.getUnsafe(typeDef.type, false, typeDef) as unknown as CodecClass<T>;
|
||||
}
|
||||
|
||||
export function createClassUnsafe<T extends Codec = Codec, K extends string = string> (registry: Registry, type: K): CodecClass<T> {
|
||||
|
||||
@@ -80,7 +80,7 @@ export function createTypeUnsafe<T extends Codec = Codec, K extends string = str
|
||||
firstError = new Error(`createType(${type}):: ${(error as Error).message}`);
|
||||
}
|
||||
|
||||
if (Clazz && Clazz.__fallbackType) {
|
||||
if (Clazz?.__fallbackType) {
|
||||
try {
|
||||
Clazz = createClassUnsafe(registry, Clazz.__fallbackType as unknown as K);
|
||||
|
||||
|
||||
@@ -8,7 +8,7 @@ import { isNumber, isUndefined, objectSpread, stringify } from '@polkadot/util';
|
||||
|
||||
import { TypeDefInfo } from '../types/index.js';
|
||||
|
||||
type ToString = { toString: () => string };
|
||||
interface ToString { toString: () => string }
|
||||
|
||||
const stringIdentity = <T extends ToString> (value: T): string => value.toString();
|
||||
|
||||
@@ -56,7 +56,11 @@ function encodeSubTypes (registry: Registry, sub: TypeDef[], asEnum?: boolean, e
|
||||
for (let i = 0, count = sub.length; i < count; i++) {
|
||||
const def = sub[i];
|
||||
|
||||
inner[def.name as string] = encodeTypeDef(registry, def);
|
||||
if (!def.name) {
|
||||
throw new Error(`No name found in ${stringify(def)}`);
|
||||
}
|
||||
|
||||
inner[def.name] = encodeTypeDef(registry, def);
|
||||
}
|
||||
|
||||
return stringify(
|
||||
|
||||
@@ -218,7 +218,7 @@ function _decodeDoNotConstruct (value: TypeDef, type: string, _: string): TypeDe
|
||||
}
|
||||
|
||||
function hasWrapper (type: string, [start, end]: [string, string, TypeDefInfo, any?]): boolean {
|
||||
return (type.substring(0, start.length) === start) && (type.slice(-1 * end.length) === end);
|
||||
return (type.startsWith(start)) && (type.slice(-1 * end.length) === end);
|
||||
}
|
||||
|
||||
const nestedExtraction: [string, string, TypeDefInfo, (value: TypeDef, type: string, subType: string, count: number) => TypeDef][] = [
|
||||
|
||||
Reference in New Issue
Block a user