-
Notifications
You must be signed in to change notification settings - Fork 36.1k
Reduce as any for notebooks #277044
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Reduce as any for notebooks #277044
Conversation
There was a problem hiding this 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 anycasts 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 |
| debug() { } | ||
| info() { } | ||
| warn() { } | ||
| error() { } | ||
| trace() { } |
Copilot
AI
Nov 13, 2025
There was a problem hiding this comment.
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.
| 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) { } |
| const value = internalMetadata[k] ?? undefined; | ||
| // eslint-disable-next-line local/code-no-any-casts | ||
| newInternalMetadata[k] = value as any; | ||
| (newInternalMetadata[k] as unknown) = value; |
Copilot
AI
Nov 13, 2025
There was a problem hiding this comment.
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].
| (newInternalMetadata[k] as unknown) = value; | |
| newInternalMetadata[k] = value as NotebookCellInternalMetadata[typeof k]; |
| 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; |
Copilot
AI
Nov 13, 2025
There was a problem hiding this comment.
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.
| super.dispose(); | ||
| // eslint-disable-next-line local/code-no-any-casts | ||
| (this.foldingDelegate as any) = null; | ||
| (this.foldingDelegate as unknown) = null; |
Copilot
AI
Nov 13, 2025
There was a problem hiding this comment.
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.
| (this.foldingDelegate as unknown) = null; | |
| (this.foldingDelegate as any) = null; |
No description provided.