Skip to content

Conversation

@rebornix
Copy link
Member

No description provided.

Copilot AI review requested due to automatic review settings November 13, 2025 00:37
@rebornix rebornix enabled auto-merge November 13, 2025 00:37
@vs-code-engineering vs-code-engineering bot added this to the November 2025 milestone Nov 13, 2025
Copilot finished reviewing on behalf of rebornix November 13, 2025 00:42
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 systematically reduces the use of as any type casts in notebook-related code, replacing them with more specific type assertions. The changes span test files and source files across the notebook contribution area.

Key Changes

  • Replaced as any casts with more specific types in test mocks and assertions
  • Enhanced type safety in notebook model metadata handling
  • Improved type annotations for mock services in tests

Reviewed Changes

Copilot reviewed 17 out of 17 changed files in this pull request and generated 4 comments.

Show a summary per file
File Description
src/vs/workbench/contrib/notebook/test/browser/notebookEditorModel.test.ts Removed unused test property assignment; replaced {} as any with properly typed parameters for model.save()
src/vs/workbench/contrib/notebook/test/browser/notebookCellLayoutManager.test.ts Added proper interface implementations for mock classes but with incorrect method signatures for MockLoggingService
src/vs/workbench/contrib/notebook/test/browser/diff/notebookDiff.test.ts Replaced as any with as unknown as SideBySideDiffElementViewModel for consistent type casting
src/vs/workbench/contrib/notebook/test/browser/diff/editorHeightCalculator.test.ts Attempted to replace as any with as FontInfo but the partial object doesn't satisfy the full interface
src/vs/workbench/contrib/notebook/test/browser/contrib/notebookOutline.test.ts Replaced as any with as NotebookOutlineEntryFactory for clearer type intent
src/vs/workbench/contrib/notebook/test/browser/NotebookEditorWidgetService.test.ts Improved type casts from as any to as HTMLElement and as IEditorPart
src/vs/workbench/contrib/notebook/common/model/notebookTextModel.ts Removed unnecessary as any cast in metadata assignment; introduced problematic (property as unknown) = value pattern
src/vs/workbench/contrib/notebook/common/model/notebookCellTextModel.ts Removed unnecessary as any cast from reduce operation return value
src/vs/workbench/contrib/notebook/browser/viewParts/notebookKernelQuickPickStrategy.ts Replaced (metaData as any)?.metadata?.language_info?.name with explicit type casting through intermediate variables
src/vs/workbench/contrib/notebook/browser/viewParts/notebookHorizontalTracker.ts Changed as any to as unknown as IMouseWheelEvent for mouse wheel event delegation
src/vs/workbench/contrib/notebook/browser/viewParts/notebookEditorStickyScroll.ts Changed as any as IMouseWheelEvent to as unknown as IMouseWheelEvent for consistency
src/vs/workbench/contrib/notebook/browser/viewModel/markupCellViewModel.ts Attempted to replace as any with as unknown in property assignment, but introduced incorrect syntax
src/vs/workbench/contrib/notebook/browser/view/renderers/webviewPreloads.ts Replaced as any with typed object literals and verbose type assertions for global APIs
src/vs/workbench/contrib/notebook/browser/controller/notebookIndentationActions.ts Replaced as any with as Record<string, unknown> for configuration values
src/vs/workbench/contrib/notebook/browser/controller/coreActions.ts Improved type guard with intersection type instead of as any for $mid property check
extensions/notebook-renderers/src/test/notebookRenderer.test.ts Replaced [] as any with proper Blob and Uint8Array instances in mock output items
extensions/notebook-renderers/src/index.ts Replaced as any with as unknown as string for setAttribute value casting

Comment on lines +34 to +38
debug() { }
info() { }
warn() { }
error() { }
trace() { }
Copy link

Copilot AI Nov 13, 2025

Choose a reason for hiding this comment

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

The mock methods for INotebookLoggingService are missing required parameters. According to the interface definition, all methods (debug, info, warn, error, trace) should accept two parameters: category: string and output: string. The current implementation has empty parameter lists which creates an incorrect mock.

Suggested change
debug() { }
info() { }
warn() { }
error() { }
trace() { }
debug(category: string, output: string) { }
info(category: string, output: string) { }
warn(category: string, output: string) { }
error(category: string, output: string) { }
trace(category: string, output: string) { }

Copilot uses AI. Check for mistakes.
const value = internalMetadata[k] ?? undefined;
// eslint-disable-next-line local/code-no-any-casts
newInternalMetadata[k] = value as any;
(newInternalMetadata[k] as unknown) = value;
Copy link

Copilot AI Nov 13, 2025

Choose a reason for hiding this comment

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

The type cast (newInternalMetadata[k] as unknown) = value is problematic. Casting the left-hand side of an assignment to unknown doesn't properly type the assignment. The original issue was that value has type T | null | undefined (after the ?? undefined) while newInternalMetadata[k] expects T | undefined. The correct fix should be newMetadata[k] = value (like line 1113) or newInternalMetadata[k] = value as NotebookCellInternalMetadata[typeof k].

Suggested change
(newInternalMetadata[k] as unknown) = value;
newInternalMetadata[k] = value as NotebookCellInternalMetadata[typeof k];

Copilot uses AI. Check for mistakes.
suite(suiteTitle, () => {
// eslint-disable-next-line local/code-no-any-casts
const fontInfo: FontInfo = { lineHeight: 18, fontSize: 18 } as any;
const fontInfo: FontInfo = { lineHeight: 18, fontSize: 18 } as FontInfo;
Copy link

Copilot AI Nov 13, 2025

Choose a reason for hiding this comment

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

The cast to FontInfo is incorrect. The object { lineHeight: 18, fontSize: 18 } does not satisfy the FontInfo class, which requires many additional properties (like fontFamily, isMonospace, typicalHalfwidthCharacterWidth, etc.). Since the DiffEditorHeightCalculatorService constructor only requires lineHeight: number, this should either be fontInfo.lineHeight passed directly, or cast to Pick<FontInfo, 'lineHeight' | 'fontSize'> or similar partial type.

Copilot uses AI. Check for mistakes.
super.dispose();
// eslint-disable-next-line local/code-no-any-casts
(this.foldingDelegate as any) = null;
(this.foldingDelegate as unknown) = null;
Copy link

Copilot AI Nov 13, 2025

Choose a reason for hiding this comment

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

The type cast (this.foldingDelegate as unknown) = null is incorrect. You cannot assign to a value of type unknown. The intent is to bypass the readonly modifier to set foldingDelegate to null for cleanup. The correct pattern would be either (this as any).foldingDelegate = null or (this.foldingDelegate as any) = null to properly bypass TypeScript's type checking.

Suggested change
(this.foldingDelegate as unknown) = null;
(this.foldingDelegate as any) = null;

Copilot uses AI. Check for mistakes.
@rebornix rebornix merged commit 8a1dbe0 into main Nov 13, 2025
33 of 34 checks passed
@rebornix rebornix deleted the rebornix/colossal-mammal branch November 13, 2025 01:23
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