Skip to content

feat: make icon type a restricted string union#699

Open
fateeand wants to merge 2 commits into
next-majorfrom
624-make-icontype-a-restricted-union
Open

feat: make icon type a restricted string union#699
fateeand wants to merge 2 commits into
next-majorfrom
624-make-icontype-a-restricted-union

Conversation

@fateeand

@fateeand fateeand commented Jul 8, 2026

Copy link
Copy Markdown
Collaborator

This PR targets the next-major branch, rather than master, as it is part of the next major version update.

Summary

IconType was defined as (typeof iconNames)[number], but since iconNames wasn't declared as const, it widened to plain string - so it accepted (and silently allowed typos in) any string, defeating the point of the type and losing IDE autocomplete. iconNames is now declared as const, so the type is a real restricted union of the actual icon names (plus '' for "no icon" as a fallback state).

While in there, the icon-related public type names were also renamed to be consistently Cps-prefixed, and a few small internal cleanups were made to cps-toast and the internal API-docs generator.

⚠️ Breaking changes

  • IconType is now a real restricted union, not string. Any code passing a string that isn't a valid icon name (or '') to an icon/prefixIcon/etc. prop will now fail to compile.
  • Renamed public exports from cps-ui-kit:
    • IconTypeCpsIconType
    • iconNamescpsIconNames
    • iconSizeTypeCpsIconSizeType
    • ICONS_PATHCPS_ICONS_PATH
  • CpsSidebarMenuItem.icon changed from string to CpsIconType.
  • CpsDialogConfig.headerIcon changed from string to CpsIconType.
  • CpsTableComponent/CpsTreeTableComponenttoolbarIcon, actionBtnIcon, and additionalBtnOnSelectIcon inputs changed from string to CpsIconType.

Migration guide

// before
import { ICONS_PATH, iconNames, type IconType, type iconSizeType } from 'cps-ui-kit';

// after
import { CPS_ICONS_PATH, cpsIconNames, type CpsIconType, type CpsIconSizeType } from 'cps-ui-kit';

Any icon prop values (icon, prefixIcon, toolbarIcon, actionBtnIcon, additionalBtnOnSelectIcon, CpsSidebarMenuItem.icon, CpsDialogConfig.headerIcon, etc.) must now be one of the values exported in cpsIconNames, or '' for no icon.

Other changes

  • cps-toast: the icon-per-notification-type mapping was a getter re-evaluated on every change detection cycle; it's now computed once in ngOnInit (matching how color is already computed) and stored as a field.
  • cps-toast: removed redundant optional chaining on data/config (both are required, always-bound inputs), replaced constructor-injected NgZone with inject(), and gave timeout a proper type (ReturnType<typeof setTimeout> | null) instead of any.
  • api-generator.js: fixed API-docs generation for type aliases shaped like typeof someArray[number] | '' — it previously only expanded a bare typeof X[number] into a readable literal union, not one nested in a top-level union, so CpsIconType's generated docs showed the unhelpful typeof cpsIconNames[number] | "" instead of the actual list of icon names. Regenerated all affected api-data/*.json files.

Release notes:

  • Make icon type a restricted string union

@github-actions

github-actions Bot commented Jul 8, 2026

Copy link
Copy Markdown
Contributor

Coverage report for library

St.
Category Percentage Covered / Total
🟡 Statements 67.95% 5647/8311
🔴 Branches 57.4% 2452/4272
🟡 Functions 68.02% 1059/1557
🟡 Lines 68.98% 5276/7649

Test suite run success

2193 tests passing in 63 suites.

Report generated by 🧪jest coverage report action from a56a624

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Pull request overview

Tightens the icon API surface in cps-ui-kit by making the icon name type a true restricted string-literal union (improving autocomplete and catching typos), renaming related public exports to consistent Cps* names, and updating downstream usage and generated API docs accordingly.

Changes:

  • Make cpsIconNames a const tuple and expose CpsIconType = (typeof cpsIconNames)[number] | '', plus rename icon-related exports (CPS_ICONS_PATH, CpsIconSizeType, etc.).
  • Update components/services/composition pages to use CpsIconType/CpsIconSizeType instead of loose string/old type names, plus small internal cleanups (e.g., cps-toast).
  • Improve the API docs generator to expand typeof SomeArray[number] even when it appears within a top-level union, and regenerate affected api-data/*.json.

Reviewed changes

Copilot reviewed 42 out of 42 changed files in this pull request and generated 2 comments.

Show a summary per file
File Description
projects/cps-ui-kit/src/lib/services/cps-notification/internal/components/cps-toast/cps-toast.component.ts Computes toast icon once, switches to inject(NgZone), and tightens timeout typing.
projects/cps-ui-kit/src/lib/services/cps-notification/internal/components/cps-toast/cps-toast.component.html Binds toast icon via a typed component field rather than string concatenation in-template.
projects/cps-ui-kit/src/lib/services/cps-dialog/utils/cps-dialog-ref.ts Converts CpsDialogComponent import to type-only import.
projects/cps-ui-kit/src/lib/services/cps-dialog/utils/cps-dialog-config.ts Changes headerIcon to CpsIconType and uses type-only imports.
projects/cps-ui-kit/src/lib/services/cps-dialog/cps-dialog.service.spec.ts Updates test icon name to a valid CpsIconType value.
projects/cps-ui-kit/src/lib/components/internal/cps-base-tree-dropdown/cps-base-tree-dropdown.component.ts Migrates icon-related inputs to CpsIconType/CpsIconSizeType.
projects/cps-ui-kit/src/lib/components/cps-tree-table/cps-tree-table.component.ts Migrates toolbar/action icon inputs to CpsIconType.
projects/cps-ui-kit/src/lib/components/cps-table/cps-table.component.ts Migrates toolbar/action icon inputs to CpsIconType.
projects/cps-ui-kit/src/lib/components/cps-sidebar-menu/cps-sidebar-menu.component.ts Changes sidebar menu item icon to CpsIconType.
projects/cps-ui-kit/src/lib/components/cps-sidebar-menu/cps-sidebar-menu.component.spec.ts Updates test data icon strings to valid icon names.
projects/cps-ui-kit/src/lib/components/cps-select/cps-select.component.ts Migrates prefix icon inputs to CpsIconType/CpsIconSizeType.
projects/cps-ui-kit/src/lib/components/cps-input/cps-input.component.ts Migrates prefix icon inputs to CpsIconType/CpsIconSizeType and type-only imports.
projects/cps-ui-kit/src/lib/components/cps-info-circle/cps-info-circle.component.ts Migrates size type to CpsIconSizeType and uses type-only imports.
projects/cps-ui-kit/src/lib/components/cps-icon/cps-icon.component.ts Renames public exports and makes icon names a const tuple; defines CpsIconType union.
projects/cps-ui-kit/src/lib/components/cps-icon/cps-icon.component.spec.ts Updates tests for renamed injection token CPS_ICONS_PATH.
projects/cps-ui-kit/src/lib/components/cps-expansion-panel/cps-expansion-panel.component.ts Migrates prefixIcon to CpsIconType.
projects/cps-ui-kit/src/lib/components/cps-chip/cps-chip.component.ts Migrates icon to CpsIconType.
projects/cps-ui-kit/src/lib/components/cps-checkbox/cps-checkbox.component.ts Migrates icon to CpsIconType.
projects/cps-ui-kit/src/lib/components/cps-button/cps-button.component.ts Migrates icon to CpsIconType and uses type-only imports.
projects/cps-ui-kit/src/lib/components/cps-autocomplete/cps-autocomplete.component.ts Migrates prefix icon inputs to CpsIconType/CpsIconSizeType.
projects/composition/src/app/pages/tab-group-page/tab-group-page.component.ts Updates tab icon typing to CpsIconType for composition examples.
projects/composition/src/app/pages/icons-page/icons-page/icons-page.component.ts Uses cpsIconNames/CpsIconType for icon list and filtering.
projects/composition/src/app/components/dialog-content/dialog-content.component.ts Types dialog content icon as CpsIconType.
projects/composition/src/app/api-data/types_map.json Updates type mapping to CpsIconType/CpsIconSizeType.
projects/composition/src/app/api-data/internal.json Updates generated type names for icon-related props.
projects/composition/src/app/api-data/cps-tree-table.json Updates generated prop types to CpsIconType for tree-table icons.
projects/composition/src/app/api-data/cps-tree-select.json Updates generated prop types to CpsIconType/CpsIconSizeType.
projects/composition/src/app/api-data/cps-tree-autocomplete.json Updates generated prop types to CpsIconType/CpsIconSizeType.
projects/composition/src/app/api-data/cps-table.json Updates generated prop types to CpsIconType for table icons.
projects/composition/src/app/api-data/cps-sidebar-menu.json Updates generated CpsSidebarMenuItem.icon type to CpsIconType.
projects/composition/src/app/api-data/cps-select.json Updates generated prop types to CpsIconType/CpsIconSizeType.
projects/composition/src/app/api-data/cps-input.json Updates generated prop types to CpsIconType/CpsIconSizeType.
projects/composition/src/app/api-data/cps-info-circle.json Updates generated prop type to CpsIconSizeType.
projects/composition/src/app/api-data/cps-icon.json Updates generated types to CpsIconType/CpsIconSizeType and expands the literal union.
projects/composition/src/app/api-data/cps-expansion-panel.json Updates generated prop type to CpsIconType.
projects/composition/src/app/api-data/cps-dialog.json Updates generated headerIcon type to CpsIconType.
projects/composition/src/app/api-data/cps-chip.json Updates generated prop type to CpsIconType.
projects/composition/src/app/api-data/cps-checkbox.json Updates generated prop type to CpsIconType.
projects/composition/src/app/api-data/cps-button.json Updates generated prop type to CpsIconType.
projects/composition/src/app/api-data/cps-autocomplete.json Updates generated prop types to CpsIconType/CpsIconSizeType.
api-generator/api-generator.js Enhances union expansion for `typeof SomeArray[number]
.github/workflows/check_pr_title_cc.yml Enables PR title conventional-commit checks on next-major in addition to master.

@github-actions

github-actions Bot commented Jul 8, 2026

Copy link
Copy Markdown
Contributor

Playwright test results

passed  112 passed

Details

stats  112 tests across 4 suites
duration  4 minutes, 42 seconds
commit  a56a624
info  For details, download the Playwright report

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

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants