Skip to content

Comments

Improve type safety for component deduplication cache#1457

Closed
Copilot wants to merge 2 commits intofix/prevent-component-duplicationfrom
copilot/sub-pr-1456
Closed

Improve type safety for component deduplication cache#1457
Copilot wants to merge 2 commits intofix/prevent-component-duplicationfrom
copilot/sub-pr-1456

Conversation

Copy link

Copilot AI commented Nov 7, 2025

Addresses type safety feedback on PR #1456 regarding the pkgs Record type in extractor.ts.

Changes

  • Changed pkgs type from Record<string, CDX.Models.Component> to Record<string, CDX.Models.Component | undefined> to correctly model index access behavior
  • Removed redundant type assertion as undefined | typeof pkgs[keyof typeof pkgs]
  • Added .filter(isNonNullable) to return statement to satisfy type constraints

Rationale

Index access on Record<K, V> returns V | undefined at runtime when the key doesn't exist. The original type was inaccurate and required workaround type assertions. The updated type correctly reflects this behavior:

const pkgs: Record<string, CDX.Models.Component | undefined> = {}
// ...
let component = pkgs[pkg.path]  // correctly typed as Component | undefined
if (component === undefined) {
  component = this.makeComponent(pkg, collectEvidence, logger)
  pkgs[pkg.path] = component
}

💡 You can make Copilot smarter by setting up custom instructions, customizing its development environment and configuring Model Context Protocol (MCP) servers. Learn more Copilot coding agent tips in the docs.

Copilot AI self-assigned this Nov 7, 2025
Co-authored-by: jkowalleck <2765863+jkowalleck@users.noreply.github.com>
Copilot AI changed the title [WIP] Fix component duplication issue in PR #1456 Improve type safety for component deduplication cache Nov 7, 2025
Copilot AI requested a review from jkowalleck November 7, 2025 13:38
@jkowalleck jkowalleck closed this Nov 7, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants