From a9806f67abe9c7750418201a89e69f23516823b2 Mon Sep 17 00:00:00 2001 From: aniketsingh1023 Date: Thu, 14 May 2026 21:51:32 +0530 Subject: [PATCH] refactor(webapp): replace any types in auth directive and training-card guard MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Part of #10883. - auth.directive.ts: replace `mmAuthAny?: any` with a narrow union reflecting the runtime branches in `dynamicChecks` (a value is either `true` for short-circuit allow, a single permission name, or an AND-group of permission names; the input accepts a single value or an array of them representing OR-of-AND-groups). - training-card.guard.provider.ts: replace `CanDeactivate` and `component: any` with `unknown`. The guard doesn't use the component parameter — `unknown` matches the actual contract while avoiding the `any` escape hatch. No runtime behavior changes. The new types match the existing call sites (no compile errors expected). --- webapp/src/ts/directives/auth.directive.ts | 17 ++++++++++++++++- webapp/src/ts/training-card.guard.provider.ts | 4 ++-- 2 files changed, 18 insertions(+), 3 deletions(-) diff --git a/webapp/src/ts/directives/auth.directive.ts b/webapp/src/ts/directives/auth.directive.ts index 339f4dbf326..df139f7506d 100644 --- a/webapp/src/ts/directives/auth.directive.ts +++ b/webapp/src/ts/directives/auth.directive.ts @@ -2,12 +2,27 @@ import * as _ from 'lodash-es'; import { Directive, Input, HostBinding, OnChanges } from '@angular/core'; import { AuthService } from '../services/auth.service'; +/** + * A single property accepted by `mmAuthAny`. Reflects the runtime branches + * in the directive's `dynamicChecks`: + * - `true` -> short-circuit allow (line: mmAuthAny.some(p => p === true)) + * - string -> a single permission name + * - string[] -> an AND-group of permission names (flattened via _.flattenDeep) + */ +type AuthAnyValue = boolean | string | string[]; + +/** + * `mmAuthAny` accepts either a single AuthAnyValue (auto-wrapped to a one-element array + * at runtime) or an array of them representing OR-of-AND-groups. + */ +type AuthAnyInput = AuthAnyValue | AuthAnyValue[]; + @Directive({ selector: '[mmAuth]' }) export class AuthDirective implements OnChanges { @Input() mmAuth?: string; - @Input() mmAuthAny?: any; + @Input() mmAuthAny?: AuthAnyInput; @Input() mmAuthOnline?: boolean; private hidden = true; diff --git a/webapp/src/ts/training-card.guard.provider.ts b/webapp/src/ts/training-card.guard.provider.ts index edd612acd5e..93de3276c8a 100644 --- a/webapp/src/ts/training-card.guard.provider.ts +++ b/webapp/src/ts/training-card.guard.provider.ts @@ -9,7 +9,7 @@ import { Selectors } from '@mm-selectors/index'; @Injectable({ providedIn: 'root' }) -export class TrainingCardDeactivationGuardProvider implements CanDeactivate { +export class TrainingCardDeactivationGuardProvider implements CanDeactivate { private readonly globalActions: GlobalActions; constructor(private readonly store: Store) { @@ -17,7 +17,7 @@ export class TrainingCardDeactivationGuardProvider implements CanDeactivate } canDeactivate( - component: any, + component: unknown, currentRoute: ActivatedRouteSnapshot, currentState: RouterStateSnapshot, nextState: RouterStateSnapshot,