Skip to content

Conversation

@DonJayamanne
Copy link
Contributor

For #276071

Copilot AI review requested due to automatic review settings November 9, 2025 03:50
@DonJayamanne DonJayamanne self-assigned this Nov 9, 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 pull request refactors the codebase to replace uses of the in operator for type narrowing with a new hasKey type guard function. The primary goal is to improve type safety and enable better TypeScript type narrowing for union types, while also addressing ESLint warnings about the use of the in operator.

  • Introduces a hasKey function in both core (src/vs/base/common/types.ts) and extension code (extensions/ipynb/src/common.ts) for type-safe property checking
  • Updates multiple notebook-related files to use hasKey for discriminating union types
  • Simplifies some property existence checks by removing redundant in operator checks where type checks are sufficient
  • Removes affected files from ESLint's code-no-in-operator rule ignore list

Reviewed Changes

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

Show a summary per file
File Description
src/vs/workbench/contrib/notebook/common/notebookEditorModel.ts Imports and uses hasKey to check for hasState method on working copy
src/vs/workbench/contrib/notebook/common/model/notebookTextModel.ts Uses hasKey extensively to narrow down ICellEditOperation union types by checking for discriminating properties like index, handle, and outputs
src/vs/workbench/contrib/notebook/browser/view/cellParts/cellExecution.ts Uses hasKey to check for affectsCell method in execution event
src/vs/workbench/contrib/notebook/browser/diff/diffElementViewModel.ts Replaces in operator with Object.hasOwn for checking cell metadata keys
src/vs/workbench/contrib/notebook/browser/contrib/find/findModel.ts Uses hasKey to discriminate find option types by checking for index property
src/vs/workbench/contrib/notebook/browser/contrib/debug/notebookBreakpoints.ts Uses hasKey to check for uri property when filtering breakpoints
extensions/notebook-renderers/src/index.ts Removes redundant in checks and adds type assertions for metadata, simplifying the code
extensions/ipynb/src/serializers.ts Imports and uses hasKey for type narrowing, removes redundant in check for indentAmount
extensions/ipynb/src/notebookImagePaste.ts Simplifies attachment existence check by using direct property access instead of in operator
extensions/ipynb/src/deserializers.ts Changes parameter type from IBaseCell to ICell and removes redundant in check for id property
extensions/ipynb/src/common.ts Adds hasKey function implementation for use within the extension
eslint.config.js Removes files from the code-no-in-operator rule ignore list now that they no longer use the in operator for type narrowing

@DonJayamanne DonJayamanne marked this pull request as ready for review November 9, 2025 06:45
@DonJayamanne DonJayamanne enabled auto-merge (squash) November 9, 2025 06:45
@vs-code-engineering vs-code-engineering bot added this to the November 2025 milestone Nov 9, 2025
@DonJayamanne DonJayamanne merged commit b282eee into main Nov 9, 2025
28 checks passed
@DonJayamanne DonJayamanne deleted the don/pleasant-gull branch November 9, 2025 07:07
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.

3 participants