[base-controller] Fix getRestricted
not inferring allowlists as empty, when they are omitted in both function and generic arguments
#4033
Labels
References
getRestricted
method: aligns runtime and type-level handling of omitted or empty inputs #4013Description
The issue is observed when calling the
ControllerMessenger
class methodgetRestricted
.Repro steps
getRestricted
generic and function params.messenger
option in the controller constructor.Following these steps prevents the
Allowed{Action,Event}
generic defaults (never
) from being applied.Allowed{Action,Event}
are inferred as their generic constraints instead (NotNamespacedBy<...>
).Currently known fixes
Objective
getRestricted
orRestrictedControllerMessenger
, and doesn't require the consumer to take actions at the call site.getRestricted
without experiencing unexpected behavior.Details
Error
Example A
NotNamespacedBy
,NarrowToAllowed
are working correctly.getRestricted
orRestrictedControllerMessenger
constructor.Example B
No error, but full allowlist is inferred despite being omitted from generic + function arguments.
In this case, the code is relying on this bug to implement a
SelectedNetworkControllerMessenger
while conveniently sidestepping the need to supply allowlists.This is dangerous behavior (especially at runtime) that should not be possible. The code should be breaking from the lack of explicitly supplied function-param allowlists.
SelectedNetworkMiddleware.test.ts
:Example C
Same behavior as Example B once this diff is applied:
Fixes
never
as generic paramsThe text was updated successfully, but these errors were encountered: