Skip to content

Make type signature of groupBy more accurate#272395

Merged
roblourens merged 1 commit intomainfrom
roblou/classic-elephant
Oct 21, 2025
Merged

Make type signature of groupBy more accurate#272395
roblourens merged 1 commit intomainfrom
roblou/classic-elephant

Conversation

@roblourens
Copy link
Member

See #272263, it currently assumes that all keys of K will be defined. This still isn't perfect, because it says that the returned object might contain a key with value undefined, but in reality, if a key is defined, it will have a value. So now usages of this with Object.entries and so on are slighly wrong, but that's preferable IMO.

See #272263, it currently assumes that all keys of K will be defined. This still isn't perfect, because it says that the returned object might contain a key with value `undefined`, but in reality, if a key is defined, it will have a value. So now usages of this with Object.entries and so on are slighly wrong, but that's preferable IMO.
Copilot AI review requested due to automatic review settings October 21, 2025 02:57
@roblourens roblourens enabled auto-merge (squash) October 21, 2025 02:57
@roblourens roblourens self-assigned this Oct 21, 2025
Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull Request Overview

This PR updates the type signature of the groupBy function to more accurately reflect that not all keys of type K will necessarily be present in the returned object. The return type is changed from Record<K, V[]> to Partial<Record<K, V[]>>, indicating that keys may be undefined.

Key changes:

  • Modified groupBy function signature to return Partial<Record<K, V[]>> instead of Record<K, V[]>
  • Added null/undefined checks and non-null assertions across the codebase where groupBy results are accessed

Reviewed Changes

Copilot reviewed 9 out of 9 changed files in this pull request and generated 1 comment.

Show a summary per file
File Description
src/vs/base/common/collections.ts Updated groupBy return type to Partial<Record<K, V[]>>
src/vs/base/test/common/collections.test.ts Added optional chaining when accessing grouped results in tests
src/vs/workbench/contrib/scm/browser/scmHistoryViewPane.ts Added null checks for historyItemRefs before and after grouping
src/vs/workbench/contrib/notebook/browser/viewModel/notebookViewModelImpl.ts Added non-null assertion when accessing grouped result
src/vs/workbench/contrib/mcp/browser/mcpCommands.ts Added non-null assertions when accessing and iterating grouped servers
src/vs/workbench/contrib/markers/test/browser/markersModel.test.ts Added null check before accessing grouped markers
src/vs/workbench/contrib/issue/browser/baseIssueReporterService.ts Added nullish coalescing for themes array and default empty array
src/vs/workbench/contrib/chat/browser/modelPicker/modePickerActionItem.ts Added optional chaining and nullish coalescing for builtin modes
src/vs/base/common/lifecycle.ts Added null check when iterating over continuations

Comment on lines +507 to +509
if (!historyItemRefs) {
continue;
}
Copy link

Copilot AI Oct 21, 2025

Choose a reason for hiding this comment

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

This null check appears redundant. The variable historyItemRefs comes from iterating over historyItemGroups (line 503) which should already be filtered or validated. If this check is necessary, it suggests the source collection may contain invalid data that should be handled earlier in the data flow.

Copilot uses AI. Check for mistakes.
Copy link
Member

Choose a reason for hiding this comment

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

Copy link
Member Author

Choose a reason for hiding this comment

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

TS doesn't know this

@vs-code-engineering vs-code-engineering bot added this to the October 2025 milestone Oct 21, 2025
Copy link
Member

@bpasero bpasero left a comment

Choose a reason for hiding this comment

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

🙏

@roblourens roblourens merged commit b9480e9 into main Oct 21, 2025
28 checks passed
@roblourens roblourens deleted the roblou/classic-elephant branch October 21, 2025 04:13
@vs-code-engineering vs-code-engineering bot locked and limited conversation to collaborators Dec 5, 2025
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants