Skip to content

Replace unsafe/legacy types in ui-kit/form-controls autocomplete family (#728) - #755

Open
fpigeonjr wants to merge 3 commits into
masterfrom
gh-728-replace-unsafe-legacy-types-in-ui-kit-form-con
Open

fpigeonjr wants to merge 3 commits into
masterfrom
gh-728-replace-unsafe-legacy-types-in-ui-kit-form-con

Conversation

@fpigeonjr

Copy link
Copy Markdown
Contributor

Description

Replaces any, unsafe function types, and legacy untyped callbacks across the autocomplete component family in src/ui-kit/form-controls, following the approach established in #706 and #732.

Scope:

  • autocomplete/autocomplete.component.ts: introduced AutocompleteItem (Record<string, unknown>), typed options/categories/enterEvent/httpRequest/cache/keyEvents/propogateChange/onKeydown/setSelected/writeValue/registerOnChange against string | AutocompleteItem instead of any; NG_VALUE_ACCESSOR typed as 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>)
  • autocomplete-multiselect/autocomplete-multiselect.component.ts: introduced MultiselectItem and CategorizedList<T>; typed options/categories/serviceOptions/itemTemplate/writeValue/registerOnChange and NodeList selection helpers
  • sam-sds-autocomplete/{autocomplete,autocomplete-search,selected-result}: NG_VALUE_ACCESSOR typed as Provider; writeValue/registerOnChange/registerOnTouched/propogateChange narrowed to unknown/typed callbacks; TemplateRef<unknown>; getFlatElements/checkItemSelected typed
  • sds-selected-item-model-helper.ts: typed clearItems(model: SAMSDSSelectedItemModel)
  • autocomplete-seach-test-service.spec.ts & autocomplete-search.component.spec.ts: removed any from test fixtures, introduced HierarchicalDataItem
  • formly/components/autocomplete/test.service.ts: updated to match AutocompleteService contract
  • eslint-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)

  • Documentation / configuration update → Apply maintenance label (applied tech-debt)

How to Test

  1. Run ESLint across autocomplete family: npx eslint src/ui-kit/form-controls/{autocomplete,autocomplete-multiselect,sam-sds-autocomplete} (0 warnings, 0 errors)
  2. Run baseline check: npm run lint:baseline (44 warnings, passes gate)
  3. Run unit tests: npx vitest run --coverage (176 test files, 1,936 passing)
  4. Check coverage: npm run coverage:check (passes all metrics)
  5. Verify test app AOT build: npm --prefix test-app run build

Expected 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

  • Branch name follows convention (e.g. gh-<number>-<slug>)
  • PR title starts with a verb in the imperative mood
  • I have self-reviewed my own code
  • format:check passes (npm run format:check)
  • lint passes (npm run lint)
  • build passes (cd test-app && npm run build)
  • Tests pass and coverage is reported (cd test-app && npm test)
  • If this change requires a documentation update, I have updated it accordingly

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.
@fpigeonjr fpigeonjr added the tech-debt Technical debt cleanup work label Sep 25, 2026
@fpigeonjr
fpigeonjr requested a lite review from Copilot September 25, 2026 17:36
@fpigeonjr
fpigeonjr marked this pull request as ready for review September 25, 2026 17:37
@fpigeonjr
fpigeonjr requested a review from a team as a code owner September 25, 2026 17:37

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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 High severity

Open (9)
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.

Comment thread src/ui-kit/form-controls/autocomplete/autocomplete.component.ts Outdated
Comment thread src/ui-kit/form-controls/autocomplete/autocomplete.component.ts Outdated
Comment thread src/ui-kit/form-controls/autocomplete/autocomplete.service.ts Outdated
- 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.

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

tech-debt Technical debt cleanup work

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Replace unsafe/legacy types in ui-kit/form-controls autocomplete family

2 participants