Skip to content

Commit

Permalink
chore: updated type explanation
Browse files Browse the repository at this point in the history
Signed-off-by: Logan Nguyen <logan.nguyen@swirldslabs.com>

Revert "chore: updated type explanation"

This reverts commit ecd8d6e.

Reapply "chore: updated type explanation"

This reverts commit 6756ecb1ee558c7d20fb8f7a71e2fbee70bb75ad.
  • Loading branch information
quiet-node committed Jan 31, 2025
1 parent 4653cd8 commit b8a4b7f
Showing 1 changed file with 6 additions and 6 deletions.
12 changes: 6 additions & 6 deletions packages/config-service/src/services/globalConfig.ts
Original file line number Diff line number Diff line change
Expand Up @@ -35,15 +35,15 @@ type ExtractTypeStringFromKey<K extends string> = K extends keyof typeof _CONFIG
// - 'string' -> string
// - 'boolean' -> boolean
// - 'number' -> number
// - 'array' -> unknown[]
// - 'array' -> string --- The input of type `array` will be a stringified representation, allowing it to be parsed with JSON.parse during processing.
type StringTypeToActualType<Tstr extends string> = Tstr extends 'string'
? string
: Tstr extends 'boolean'
? boolean
: Tstr extends 'number'
? number
: Tstr extends 'array'
? string // The input of type `array` will be a stringified representation, allowing it to be parsed with JSON.parse during processing.
? string
: never;

// Helper type that determines if a configuration value can be undefined
Expand All @@ -52,7 +52,7 @@ type StringTypeToActualType<Tstr extends string> = Tstr extends 'string'
// Example:
// - For ‘CHAIN_ID’ or ‘OPERATOR_ID_MAIN’ (required: true, defaultValue: null) → false (cannot be undefined as it’s a required config)
// - For ‘WEB_SOCKET_PORT’ (required: false, defaultValue: 8546) → false (cannot be undefined as it has a fallback default value)
// - For ‘WS_CONNECTION_LIMIT_PER_IP’ (required: false, defaultValue: null) → true (can be undefined as it’s not a required config and has no default value)
// - For GITHUB_PR_NUMBER (required: false, defaultValue: null) → true (can be undefined as it’s not a required config and has no default value)
type CanBeUndefined<K extends string> = K extends keyof typeof _CONFIG
? (typeof _CONFIG)[K]['required'] extends true
? false
Expand All @@ -64,9 +64,9 @@ type CanBeUndefined<K extends string> = K extends keyof typeof _CONFIG
// Type utility that maps configuration keys to their corresponding TypeScript types,
// including undefined for values that can be undefined based on their configuration.
// Example:
// - For 'CHAIN_ID' (required: true, defaultValue: null) -> string
// - For 'WEB_SOCKET_PORT' (required: false, defaultValue: 8546) -> number
// - For 'WS_CONNECTION_LIMIT_PER_IP' (required: false, defaultValue: null) -> number | undefined
// - For 'CHAIN_ID' (type: 'string', required: true, defaultValue: null) -> string
// - For 'WEB_SOCKET_PORT' (type: 'number', required: false, defaultValue: 8546) -> number
// - For 'GITHUB_PR_NUMBER' (type: 'string', required: false, defaultValue: null) -> string | undefined
export type GetTypeOfConfigKey<K extends string> = CanBeUndefined<K> extends true
? StringTypeToActualType<ExtractTypeStringFromKey<K>> | undefined
: StringTypeToActualType<ExtractTypeStringFromKey<K>>;
Expand Down

0 comments on commit b8a4b7f

Please sign in to comment.