Repository navigation
Replace unsafe/legacy types in ui-kit/form-controls autocomplete family (#728) - #755
Conversation
Replaces `any`/legacy-typed provider consts/`Function`-shaped callbacks across the autocomplete component family in src/ui-kit/form-controls, following the same approach used for the non-autocomplete slice (#732) and the parent issue #586. - autocomplete/autocomplete.component.ts: introduced AutocompleteItem (Record<string, unknown>) for key/value option objects; typed options/categories/enterEvent/httpRequest/cache/keyEvents/ propogateChange/onKeydown/setSelected/writeValue/registerOnChange against string | AutocompleteItem instead of any; NG_VALUE_ACCESSOR provider const typed as Angular's Provider - autocomplete/autocomplete.service.ts: setFetchMethod/fetch return types narrowed from any to void/unknown[] - autocomplete-multiselect/autocomplete-cache.ts: Cached/AutocompleteCache made generic (<T = unknown>) instead of any[]/any-typed members - autocomplete-multiselect/autocomplete-multiselect.component.ts: introduced MultiselectItem and CategorizedList<T> (typed replacement for the associative-array-like `list` structure sortByCategory/ filterOptions build); typed options/categories/serviceOptions/ itemTemplate/writeValue/registerOnChange and the NodeList-based selection helpers - sam-sds-autocomplete/{autocomplete,autocomplete-search,selected-result}: NG_VALUE_ACCESSOR provider consts typed as Provider; writeValue/registerOnChange/registerOnTouched/propogateChange narrowed to unknown/typed callbacks; TemplateRef<any> -> TemplateRef<unknown>; getFlatElements/checkItemSelected typed - sds-selected-item-model-helper.ts: clearItems(model: any) -> clearItems(model: SAMSDSSelectedItemModel) - autocomplete-seach-test-service.spec.ts: introduced HierarchicalDataItem interface for the sample fixture shape, replacing implicit any on loadedData/itemsListOutofObservable - autocomplete-search.component.spec.ts: removed any from local test fixture types (propagated/previous/item locals) - formly/components/autocomplete/test.service.ts: TestAutocompleteService updated to match AutocompleteService's Observable<unknown[]> contract Lowers the root ESLint warning baseline 143 -> 44 (0 errors). All previously-passing specs still pass (1936/1936); test-app build and coverage-floor gate both pass with no regression.
There was a problem hiding this comment.
Copilot review overview
🟡 Changes recommended
Critical public API compatibility and test-compilation issues remain unresolved.
Get a fresh assessment by requesting another Copilot review.
Review effort: Lite
Findings: 9
Open (9)
Record index signature breaks typed option interfaces · New CategorizedList requirement breaks plain-object callers · New Record index signature breaks typed autocomplete options · New Autocomplete categories no longer accept string labels · New Observable<unknown[]> breaks AutocompleteService consumers · New unknown callback value breaks typed fixture assignment · New Required callbacks break autocomplete-search test stubs · New Required callbacks break autocomplete wrapper test stubs · New Required callbacks break selected-result test stubs · New
What changed in this PR
This PR replaces unsafe TypeScript types across the autocomplete component family and reduces the ESLint warning baseline.
Changes:
- Adds typed autocomplete items, caches, callbacks, services, and CVA APIs.
- Updates related test fixtures and Formly typings.
- Lowers the ESLint baseline from 143 to 44 warnings.
| File | Summary |
|---|---|
src/ui-kit/form-controls/sam-sds-autocomplete/selected-result/selected-result.component.ts |
Types selected-result CVA APIs. |
src/ui-kit/form-controls/sam-sds-autocomplete/selected-result/models/sds-selected-item-model-helper.ts |
Types selected-item model clearing. |
src/ui-kit/form-controls/sam-sds-autocomplete/autocomplete/autocomplete.component.ts |
Types autocomplete CVA APIs. |
src/ui-kit/form-controls/sam-sds-autocomplete/autocomplete-search/autocomplete-search.component.ts |
Types search callbacks and helpers. |
src/ui-kit/form-controls/sam-sds-autocomplete/autocomplete-search/autocomplete-search.component.spec.ts |
Updates search test fixture types. |
src/ui-kit/form-controls/sam-sds-autocomplete/autocomplete-search/autocomplete-seach-test-service.spec.ts |
Adds typed hierarchical fixtures. |
src/ui-kit/form-controls/autocomplete/autocomplete.service.ts |
Narrows service method types. |
src/ui-kit/form-controls/autocomplete/autocomplete.component.ts |
Types autocomplete inputs and callbacks. |
src/ui-kit/form-controls/autocomplete-multiselect/autocomplete-multiselect.component.ts |
Adds typed multiselect items and helpers. |
src/ui-kit/form-controls/autocomplete-multiselect/autocomplete-cache.ts |
Makes cache implementations generic. |
src/formly/components/autocomplete/test.service.ts |
Aligns the test service contract. |
eslint-baseline.json |
Ratchets down the warning baseline. |
💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.
- MultiselectItem/AutocompleteItem: use `object` instead of
`Record<string, unknown>` so consumers' named option interfaces
(which lack a string index signature) remain assignable, matching
the old `any[]` API's compatibility.
- CategorizedList.totalItems(): make optional so structural inputs
(e.g. `{ 0: [], categories: [...] }`) built by callers/tests without
the bookkeeping method still type-check.
- SamAutocompleteComponent.categories: keep `Array<string |
AutocompleteItem>` instead of narrowing to `AutocompleteItem[]`, so
plain string category labels are still accepted.
- AutocompleteService: make generic (`AutocompleteService<T =
unknown>`) so `fetch()` returns `Observable<T[]>`; the standalone
autocomplete component parameterizes it with `string |
AutocompleteItem`, and existing untyped consumers keep compiling via
the `unknown` default.
- Updated registerOnChange/registerOnTouched spec stubs in
autocomplete-search, sam-sds-autocomplete, and selected-result specs
to pass no-op functions instead of `{}`, matching the CVA callback
signatures.
New problem found: two spec files were never updated for the signature changesWhile verifying, ran a full Confirmed via baseline diff ( Pre-existing, NOT caused by this PR (already broken at baseline — ignore):
Newly introduced by this PR (need fixing):
RecommendationFix these two spec files the same way
Re-run |
Update autocomplete.spec.ts and autocomplete-multiselect.spec.ts to match component type signatures introduced in #728: - Remove unused target property from onKeydown test calls in autocomplete.spec.ts - Type AutocompleteService and Subject test fixtures with AutocompleteItem - Cast options and category filter results to match narrowed parameter types - Cast MultiselectItem dynamic property reads (.value, .type) - Supply empty categories array on test fixture for CategorizedList
|
Addressed in c2653a0. Updated
Verification:
|

Description
Replaces
any, unsafe function types, and legacy untyped callbacks across the autocomplete component family insrc/ui-kit/form-controls, following the approach established in #706 and #732.Scope:
autocomplete/autocomplete.component.ts: introducedAutocompleteItem(Record<string, unknown>), typedoptions/categories/enterEvent/httpRequest/cache/keyEvents/propogateChange/onKeydown/setSelected/writeValue/registerOnChangeagainststring | AutocompleteIteminstead ofany;NG_VALUE_ACCESSORtyped asProviderautocomplete/autocomplete.service.ts:setFetchMethod/fetchreturn types narrowed fromanytovoid/unknown[]autocomplete-multiselect/autocomplete-cache.ts:Cached/AutocompleteCachemade generic (<T = unknown>)autocomplete-multiselect/autocomplete-multiselect.component.ts: introducedMultiselectItemandCategorizedList<T>; typedoptions/categories/serviceOptions/itemTemplate/writeValue/registerOnChangeandNodeListselection helperssam-sds-autocomplete/{autocomplete,autocomplete-search,selected-result}:NG_VALUE_ACCESSORtyped asProvider;writeValue/registerOnChange/registerOnTouched/propogateChangenarrowed tounknown/typed callbacks;TemplateRef<unknown>;getFlatElements/checkItemSelectedtypedsds-selected-item-model-helper.ts: typedclearItems(model: SAMSDSSelectedItemModel)autocomplete-seach-test-service.spec.ts&autocomplete-search.component.spec.ts: removedanyfrom test fixtures, introducedHierarchicalDataItemformly/components/autocomplete/test.service.ts: updated to matchAutocompleteServicecontracteslint-baseline.json: ratcheted down warning baseline from 143 to 44 (0 errors)Motivation and Context
Closes #728
Part of the tech debt burndown for ESLint and TypeScript safety (#580, #586). Resolves unsafe-type lint findings across the autocomplete family while preserving public API and consumer-compiled compatibility.
Type of Change (Select One and Apply Label)
maintenancelabel (appliedtech-debt)How to Test
npx eslint src/ui-kit/form-controls/{autocomplete,autocomplete-multiselect,sam-sds-autocomplete}(0 warnings, 0 errors)npm run lint:baseline(44 warnings, passes gate)npx vitest run --coverage(176 test files, 1,936 passing)npm run coverage:check(passes all metrics)npm --prefix test-app run buildExpected result: All lint checks, unit tests, coverage gates, and test-app AOT compilation pass.
Screenshots (if appropriate)
N/A — TypeScript type narrowing and lint cleanup only.
Checklist
gh-<number>-<slug>)format:checkpasses (npm run format:check)lintpasses (npm run lint)buildpasses (cd test-app && npm run build)cd test-app && npm test)