From 2e66fd30b6b267e9a1656965affcb7791a9b75cf Mon Sep 17 00:00:00 2001 From: James Cox Date: Wed, 25 Mar 2026 22:06:32 -0500 Subject: [PATCH] chore(ui): clear test and declaration any bucket Replace low-risk any usages in test harnesses, specs, and epubjs type declarations with concrete unions, unknown, or Angular form types so the no-explicit-any backlog starts shrinking without changing runtime behavior. Validation: just ui lint --- .../component/magic-shelf-component.spec.ts | 19 ++++++++++--------- .../service/magic-shelf-utils.spec.ts | 2 +- frontend/src/test-setup.ts | 8 ++++++-- frontend/src/types/epubjs.d.ts | 14 +++++++------- 4 files changed, 24 insertions(+), 19 deletions(-) diff --git a/frontend/src/app/features/magic-shelf/component/magic-shelf-component.spec.ts b/frontend/src/app/features/magic-shelf/component/magic-shelf-component.spec.ts index 27dc8c590..c5c01c0da 100644 --- a/frontend/src/app/features/magic-shelf/component/magic-shelf-component.spec.ts +++ b/frontend/src/app/features/magic-shelf/component/magic-shelf-component.spec.ts @@ -1,6 +1,7 @@ import {beforeEach, describe, expect, it, vi} from 'vitest'; import {TestBed} from '@angular/core/testing'; -import {MagicShelfComponent, Rule} from './magic-shelf-component'; +import {FormArray} from '@angular/forms'; +import {MagicShelfComponent, Rule, RuleOperator} from './magic-shelf-component'; import {TranslocoService} from '@jsverse/transloco'; import {LibraryService} from '../../book/service/library.service'; import {ShelfService} from '../../book/service/shelf.service'; @@ -365,27 +366,27 @@ describe('MagicShelfComponent (Part 3)', () => { describe('buildRuleFromData edge cases', () => { it('should handle in_between for date fields', () => { - const rule: Rule = {field: 'publishedDate', operator: 'in_between' as any, value: null, valueStart: '2024-01-01', valueEnd: '2024-12-31'}; + const rule: Rule = {field: 'publishedDate', operator: 'in_between' as RuleOperator, value: null, valueStart: '2024-01-01', valueEnd: '2024-12-31'}; const formGroup = component.buildRuleFromData(rule); expect(formGroup.get('valueStart')?.value).toBeInstanceOf(Date); expect(formGroup.get('valueEnd')?.value).toBeInstanceOf(Date); }); it('should handle in_between for number fields', () => { - const rule: Rule = {field: 'pageCount', operator: 'in_between' as any, value: null, valueStart: 100, valueEnd: 500}; + const rule: Rule = {field: 'pageCount', operator: 'in_between' as RuleOperator, value: null, valueStart: 100, valueEnd: 500}; const formGroup = component.buildRuleFromData(rule); expect(formGroup.get('valueStart')?.value).toBe(100); expect(formGroup.get('valueEnd')?.value).toBe(500); }); it('should preserve array values for includes_any', () => { - const rule: Rule = {field: 'readStatus', operator: 'includes_any' as any, value: ['READ', 'READING']}; + const rule: Rule = {field: 'readStatus', operator: 'includes_any' as RuleOperator, value: ['READ', 'READING']}; const formGroup = component.buildRuleFromData(rule); expect(formGroup.get('value')?.value).toEqual(['READ', 'READING']); }); it('should handle is_empty operator with no value', () => { - const rule: Rule = {field: 'title', operator: 'is_empty' as any, value: null}; + const rule: Rule = {field: 'title', operator: 'is_empty' as RuleOperator, value: null}; const formGroup = component.buildRuleFromData(rule); expect(formGroup.get('value')?.value).toBeNull(); }); @@ -397,7 +398,7 @@ describe('MagicShelfComponent (Part 3)', () => { }); it('should handle string values for text fields', () => { - const rule: Rule = {field: 'title', operator: 'contains' as any, value: 'Harry Potter'}; + const rule: Rule = {field: 'title', operator: 'contains' as RuleOperator, value: 'Harry Potter'}; const formGroup = component.buildRuleFromData(rule); expect(formGroup.get('value')?.value).toBe('Harry Potter'); }); @@ -499,7 +500,7 @@ describe('MagicShelfComponent (Part 3)', () => { const group = component.createGroup(); expect(group.get('type')?.value).toBe('group'); expect(group.get('join')?.value).toBe('and'); - expect((group.get('rules') as any).length).toBe(0); + expect((group.get('rules') as FormArray).length).toBe(0); }); }); @@ -623,7 +624,7 @@ describe('MagicShelfComponent (Part 3)', () => { }); it('should not contain title', () => { - const config = component.numericFieldConfigMap.get('title' as any); + const config = component.numericFieldConfigMap.get('title'); expect(config).toBeUndefined(); }); @@ -654,7 +655,7 @@ describe('MagicShelfComponent (Part 3)', () => { }; const result = component.buildGroupFromData(groupData); expect(result.get('join')?.value).toBe('or'); - const rulesArray = result.get('rules') as any; + const rulesArray = result.get('rules') as FormArray; expect(rulesArray.length).toBe(2); const nestedGroup = rulesArray.at(1); expect(nestedGroup.get('rules')).toBeDefined(); diff --git a/frontend/src/app/features/magic-shelf/service/magic-shelf-utils.spec.ts b/frontend/src/app/features/magic-shelf/service/magic-shelf-utils.spec.ts index eb360bdf8..356c0ca3d 100644 --- a/frontend/src/app/features/magic-shelf/service/magic-shelf-utils.spec.ts +++ b/frontend/src/app/features/magic-shelf/service/magic-shelf-utils.spec.ts @@ -175,7 +175,7 @@ describe('magic-shelf-utils', () => { it('should return value as-is for undefined type', () => { expect(parseValue('hello', undefined)).toBe('hello'); - expect(parseValue('true', 'boolean' as any)).toBe('true'); + expect(parseValue('true', 'boolean')).toBe('true'); }); it('should return arrays as-is for undefined type', () => { diff --git a/frontend/src/test-setup.ts b/frontend/src/test-setup.ts index 6b2404809..ad77e8484 100644 --- a/frontend/src/test-setup.ts +++ b/frontend/src/test-setup.ts @@ -3,9 +3,13 @@ import 'zone.js/testing'; import {TestBed} from '@angular/core/testing'; import {BrowserDynamicTestingModule, platformBrowserDynamicTesting} from '@angular/platform-browser-dynamic/testing'; +declare global { + var __ANGULAR_TESTBED_INITIALIZED__: boolean | undefined; +} + // Only initialize if not already initialized -if (!(globalThis as any).__ANGULAR_TESTBED_INITIALIZED__) { - (globalThis as any).__ANGULAR_TESTBED_INITIALIZED__ = true; +if (!globalThis.__ANGULAR_TESTBED_INITIALIZED__) { + globalThis.__ANGULAR_TESTBED_INITIALIZED__ = true; TestBed.initTestEnvironment( BrowserDynamicTestingModule, platformBrowserDynamicTesting(), diff --git a/frontend/src/types/epubjs.d.ts b/frontend/src/types/epubjs.d.ts index b9d77ef09..1d534bd42 100644 --- a/frontend/src/types/epubjs.d.ts +++ b/frontend/src/types/epubjs.d.ts @@ -8,7 +8,7 @@ declare module 'epubjs' { export interface Navigation { toc: TocItem[]; - get(target: string): any; + get(target: string): TocItem | undefined; } export interface Location { @@ -47,7 +47,7 @@ declare module 'epubjs' { } export interface Themes { - register(name: string, theme: any): void; + register(name: string, theme: unknown): void; select(name: string): void; override(property: string, value: string): void; font(name: string): void; @@ -61,10 +61,10 @@ declare module 'epubjs' { next(): Promise; currentLocation(): Location | null; on(event: 'relocated', callback: (location: Location) => void): void; - on(event: 'rendered', callback: (section: any) => void): void; + on(event: 'rendered', callback: (section: unknown) => void): void; on(event: 'keyup', callback: (event: KeyboardEvent) => void): void; - on(event: string, callback: any): void; - off(event: string, callback: any): void; + on(event: string, callback: (...args: unknown[]) => void): void; + off(event: string, callback: (...args: unknown[]) => void): void; destroy(): void; } @@ -91,8 +91,8 @@ declare module 'epubjs' { export class EpubCFI { compare(cfi1: string, cfi2: string): number; - prototype: any; // Allow prototype access if needed + prototype: unknown; // Allow prototype access if needed } export default function ePub(input: string | ArrayBuffer): Book; -} \ No newline at end of file +}