Skip to content

Commit

Permalink
[base-controller] minor type fixes (#4036)
Browse files Browse the repository at this point in the history
## Changelog

### `@metamask/base-controller`

#### Added

- **BREAKING**: Add `string` as generic constraint to the `Name` generic
parameter of the types `NamespacedBy` and `NotNamespacedBy`.

## Checklist

- [x] I've updated the test suite for new or updated code as appropriate
- [x] I've updated documentation (JSDoc, Markdown, etc.) for new or
updated code as appropriate
- [x] I've highlighted breaking changes using the "BREAKING" category
above as appropriate
  • Loading branch information
MajorLift authored Mar 8, 2024
1 parent 8d74b81 commit caee13a
Showing 1 changed file with 3 additions and 11 deletions.
14 changes: 3 additions & 11 deletions packages/base-controller/src/ControllerMessenger.ts
Original file line number Diff line number Diff line change
Expand Up @@ -90,12 +90,12 @@ type EventSubscriptionMap<
*/
export type NamespacedBy<
Namespace extends string,
Name,
Name extends string,
> = Name extends `${Namespace}:${string}` ? Name : never;

export type NotNamespacedBy<
Namespace extends string,
Name,
Name extends string,
> = Name extends `${Namespace}:${string}` ? never : Name;

export type NamespacedName<Namespace extends string = string> =
Expand Down Expand Up @@ -450,15 +450,7 @@ export class ControllerMessenger<
AllowedAction,
AllowedEvent
> {
return new RestrictedControllerMessenger<
Namespace,
| NarrowToNamespace<Action, Namespace>
| NarrowToAllowed<Action, AllowedAction>,
| NarrowToNamespace<Event, Namespace>
| NarrowToAllowed<Event, AllowedEvent>,
AllowedAction,
AllowedEvent
>({
return new RestrictedControllerMessenger({
controllerMessenger: this,
name,
allowedActions,
Expand Down

0 comments on commit caee13a

Please sign in to comment.