From 902b2bebe36a73d7957b5135d69fb505cd4dd923 Mon Sep 17 00:00:00 2001 From: CJ42 Date: Tue, 30 Apr 2024 16:35:26 +0100 Subject: [PATCH] refactor: add missing returned type in `getSchema` function --- src/index.ts | 11 ++++++++--- src/lib/schemaParser.ts | 21 ++++++++++++--------- 2 files changed, 20 insertions(+), 12 deletions(-) diff --git a/src/index.ts b/src/index.ts index fb4716e0..d571f779 100644 --- a/src/index.ts +++ b/src/index.ts @@ -42,6 +42,7 @@ import { encodeKeyName, isDynamicKeyName } from './lib/encodeKeyName'; import { ERC725Config, ERC725Options } from './types/Config'; import { Permissions } from './types/Method'; import { + DynamicNameSchema, ERC725JSONSchema, ERC725JSONSchemaKeyType, ERC725JSONSchemaValueContent, @@ -359,15 +360,19 @@ export class ERC725 { getSchema( keyOrKeys: string[], providedSchemas?: ERC725JSONSchema[], - ): Record; + ): Record; getSchema( keyOrKeys: string, providedSchemas?: ERC725JSONSchema[], - ): ERC725JSONSchema | null; + ): ERC725JSONSchema | DynamicNameSchema | null; getSchema( keyOrKeys: string | string[], providedSchemas?: ERC725JSONSchema[], - ): ERC725JSONSchema | null | Record { + ): + | ERC725JSONSchema + | DynamicNameSchema + | null + | Record { return getSchema( keyOrKeys, this.options.schemas.concat(providedSchemas || []), diff --git a/src/lib/schemaParser.ts b/src/lib/schemaParser.ts index bb38f3db..889fb579 100644 --- a/src/lib/schemaParser.ts +++ b/src/lib/schemaParser.ts @@ -171,7 +171,7 @@ const findMappingWithGroupingSchemaForKey = ( function schemaParser( key: string, schemas: ERC725JSONSchema[], -): ERC725JSONSchema | null { +): ERC725JSONSchema | DynamicNameSchema | null { const schemasByKeyType = getSchemasByKeyType(schemas); let foundSchema: ERC725JSONSchema | null = null; @@ -205,20 +205,23 @@ function schemaParser( export function getSchema( keyOrKeys: string | string[], providedSchemas?: ERC725JSONSchema[], -): ERC725JSONSchema | null | Record { +): + | ERC725JSONSchema + | DynamicNameSchema + | null + | Record { let fullSchema: ERC725JSONSchema[] = allSchemas; if (providedSchemas) { fullSchema = fullSchema.concat(providedSchemas); } if (Array.isArray(keyOrKeys)) { - return keyOrKeys.reduce>( - (acc, key) => { - acc[key] = schemaParser(key, fullSchema); - return acc; - }, - {}, - ); + return keyOrKeys.reduce< + Record + >((acc, key) => { + acc[key] = schemaParser(key, fullSchema); + return acc; + }, {}); } return schemaParser(keyOrKeys, fullSchema);