Skip to content

Commit 35fb5e8

Browse files
authored
Make KnownCaipNamespacedChainId generic over Namespace type parameter (#262)
This commit refactors `KnownCaipNamespacedChainId` (introduced in [#258](#258)) into a generic type by adding a `Namespace` type parameter. This allows the type to be narrowed down to chain IDs with a specific namespace. This is not a breaking change, as `Namespace` defaults to a type union of known CAIP namespaces. The type's previous behavior is preserved when its generic type parameter is omitted.
1 parent 0a6e1bd commit 35fb5e8

File tree

2 files changed

+9
-1
lines changed

2 files changed

+9
-1
lines changed

CHANGELOG.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,10 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
77

88
## [Unreleased]
99

10+
### Changed
11+
12+
- Make `KnownCaipNamespacedChainId` type generic over `Namespace` type parameter ([#262](https://github.com/MetaMask/utils/pull/262))
13+
1014
## [11.5.0]
1115

1216
### Added

src/caip-types.ts

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -148,8 +148,12 @@ export enum KnownCaipNamespace {
148148
*
149149
* This is a narrower, more type-safe alternative to {@link CaipChainId} for use cases
150150
* where the chain namespace must be one of the known standards.
151+
*
152+
* @template Namespace - The namespace of the CAIP-2 chain ID. Must be a known namespace specified in {@link KnownCaipNamespace}.
151153
*/
152-
export type KnownCaipNamespacedChainId = `${KnownCaipNamespace}:${string}`;
154+
export type KnownCaipNamespacedChainId<
155+
Namespace extends `${KnownCaipNamespace}` = `${KnownCaipNamespace}`,
156+
> = `${Namespace}:${string}`;
153157

154158
/**
155159
* Check if the given value is a {@link CaipChainId}.

0 commit comments

Comments
 (0)