Skip to content

Commit

Permalink
fix: loosen strict type checking for array types in config variables
Browse files Browse the repository at this point in the history
Signed-off-by: Logan Nguyen <[email protected]>
  • Loading branch information
quiet-node committed Jan 30, 2025
1 parent b172337 commit 6191603
Showing 1 changed file with 10 additions and 10 deletions.
20 changes: 10 additions & 10 deletions packages/config-service/src/services/globalConfig.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,15 @@
*
*/

// This type extracts the type string associated with a specific key
// in the _CONFIG object. It checks if the provided key K is a valid
// key in _CONFIG. If it is, it retrieves the 'type' property of the
// corresponding configuration object; otherwise, it resolves to 'never'.
// Example:
// - For key 'CHAIN_ID', it returns 'string' if defined in _CONFIG.
// - For an invalid key 'INVALID_KEY', it returns never.
type ExtractTypeStringFromKey<K extends string> = K extends keyof typeof _CONFIG ? (typeof _CONFIG)[K]['type'] : never;

// Type mapping utility that converts string representations of types
// (e.g., 'string', 'boolean', 'number', 'array') to their corresponding
// TypeScript types. This allows for dynamic type resolution based on
Expand All @@ -34,18 +43,9 @@ type StringTypeToActualType<Tstr extends string> = Tstr extends 'string'
: Tstr extends 'number'
? number
: Tstr extends 'array'
? unknown[]
? any[]
: never;

// This type extracts the type string associated with a specific key
// in the _CONFIG object. It checks if the provided key K is a valid
// key in _CONFIG. If it is, it retrieves the 'type' property of the
// corresponding configuration object; otherwise, it resolves to 'never'.
// Example:
// - For key 'CHAIN_ID', it returns 'string' if defined in _CONFIG.
// - For an invalid key 'INVALID_KEY', it returns never.
type ExtractTypeStringFromKey<K extends string> = K extends keyof typeof _CONFIG ? (typeof _CONFIG)[K]['type'] : never;

// This type maps a configuration key K to its corresponding TypeScript type.
// It first uses ExtractTypeStringFromKey to get the type string and then
// converts that string to the actual TypeScript type using StringTypeToActualType.
Expand Down

0 comments on commit 6191603

Please sign in to comment.