diff --git a/packages/api/src/base/util.ts b/packages/api/src/base/util.ts index ee17f4b1a5..053d5c5d13 100644 --- a/packages/api/src/base/util.ts +++ b/packages/api/src/base/util.ts @@ -4,6 +4,7 @@ import type { ApiInterfaceRx } from '@polkadot/api/types'; import type { bool } from '@polkadot/types'; import type { Releases } from '@polkadot/types/interfaces'; +import type { InterfaceTypes } from '@polkadot/types/types'; import { combineLatest, Observable, of } from '@polkadot/x-rxjs'; import { map, take } from '@polkadot/x-rxjs/operators'; @@ -11,7 +12,11 @@ import { map, take } from '@polkadot/x-rxjs/operators'; // the order and types needs to map with the all array setup below type Extracted = [bool | null, bool | null, Releases | null]; -interface DetectedTypes { +type DetectedKeys = keyof Pick; + +type DetectedValues = keyof InterfaceTypes; + +interface DetectedTypes extends Record { AccountInfo: 'AccountInfoWithRefCount' | 'AccountInfoWithProviders', ValidatorPrefs: 'ValidatorPrefsWithBlocked' | 'ValidatorPrefsWithCommission'; } diff --git a/packages/types/src/create/registry.ts b/packages/types/src/create/registry.ts index f88c34a33f..42719016e9 100644 --- a/packages/types/src/create/registry.ts +++ b/packages/types/src/create/registry.ts @@ -316,6 +316,7 @@ export class TypeRegistry implements Registry { this.#classes.set(arg1.name, arg1); } else if (isString(arg1)) { assert(isFunction(arg2), `Expected class definition passed to '${arg1}' registration`); + assert(arg1 !== arg2.toString(), `Unable to register circular ${arg1} === ${arg1}`); this.#classes.set(arg1, arg2); } else { @@ -333,6 +334,8 @@ export class TypeRegistry implements Registry { ? type : JSON.stringify(type); + assert(name !== def, `Unable to register circular ${name} === ${def}`); + // we already have this type, remove the classes registered for it if (this.#classes.has(name)) { this.#classes.delete(name);