Reduce use of explicit any type (#274723)#279751
Conversation
There was a problem hiding this comment.
Pull request overview
This PR improves type safety across the codebase by systematically replacing explicit any types with more specific types (unknown, void, proper Electron types, and concrete type definitions). This allows these files to be removed from the ESLint exception list that permits any usage.
Key Changes
- Replaced
anywithunknownfor external/unvalidated data parameters (cached data, deserialization, type guards) - Changed Promise return types from
Promise<any>toPromise<void>orPromise<unknown>as appropriate - Added proper Electron namespace types (
Electron.Debugger,Electron.Event) in electron-main code - Replaced inline type definitions with concrete types (e.g.,
Record<string, string>) - Removed unnecessary type assertions and ESLint disable comments where TypeScript inference now works correctly
Reviewed changes
Copilot reviewed 8 out of 8 changed files in this pull request and generated 1 comment.
Show a summary per file
| File | Description |
|---|---|
| src/vs/workbench/contrib/search/common/cacheState.ts | Changed loadFn parameter type from Promise<any> to Promise<unknown> for cache loading function |
| src/vs/workbench/contrib/search/browser/searchWidget.ts | Updated run() and triggerReplaceAll() return types from Promise<any> to Promise<void>, removed unnecessary Promise.resolve(null) |
| src/vs/workbench/contrib/notebook/common/notebookRange.ts | Changed type guard parameter from any to unknown and replaced old-style casts with as assertions |
| src/vs/workbench/contrib/markers/browser/markersTable.ts | Replaced generic any types with MarkerTableItem in virtual delegate, removed unnecessary type cast in filter |
| src/vs/workbench/contrib/chat/common/chatModes.ts | Changed cached modes deserialization parameter from any to unknown |
| src/vs/platform/diagnostics/node/diagnosticsService.ts | Replaced any with Record<string, string> for GPU features object |
| src/vs/platform/browserElements/electron-main/nativeBrowserElementsMainService.ts | Added proper Electron.Debugger and Electron.Event types, defined inline type for matched styles structure, removed unnecessary type annotations in arrow functions |
| eslint.config.js | Removed 7 files from the any usage exception list now that they no longer use explicit any types |
| } | ||
|
|
||
| formatMatchedStyles(matched: any): string { | ||
| formatMatchedStyles(matched: { inlineStyle?: { cssProperties?: Array<{ name: string; value: string }> }; matchedCSSRules?: Array<{ rule: { selectorList: { selectors: Array<{ text: string }> }; origin: string; style: { cssProperties: Array<{ name: string; value: string }> } } }>; inherited?: Array<{ matchedCSSRules?: Array<{ rule: { selectorList: { selectors: Array<{ text: string }> }; origin: string; style: { cssProperties: Array<{ name: string; value: string }> } } }> }> }): string { |
There was a problem hiding this comment.
The inline type definition for the matched parameter is extremely long and complex (over 300 characters on a single line), which makes it difficult to read and maintain. Consider extracting this into a separate interface or type alias above the function, such as:
interface MatchedStylesData {
inlineStyle?: { cssProperties?: Array<{ name: string; value: string }> };
matchedCSSRules?: Array<{
rule: {
selectorList: { selectors: Array<{ text: string }> };
origin: string;
style: { cssProperties: Array<{ name: string; value: string }> }
}
}>;
inherited?: Array<{
matchedCSSRules?: Array<{
rule: {
selectorList: { selectors: Array<{ text: string }> };
origin: string;
style: { cssProperties: Array<{ name: string; value: string }> }
}
}>
}>;
}
formatMatchedStyles(matched: MatchedStylesData): string {This would improve readability and make the type reusable if needed elsewhere.
| formatMatchedStyles(matched: { inlineStyle?: { cssProperties?: Array<{ name: string; value: string }> }; matchedCSSRules?: Array<{ rule: { selectorList: { selectors: Array<{ text: string }> }; origin: string; style: { cssProperties: Array<{ name: string; value: string }> } } }>; inherited?: Array<{ matchedCSSRules?: Array<{ rule: { selectorList: { selectors: Array<{ text: string }> }; origin: string; style: { cssProperties: Array<{ name: string; value: string }> } } }> }> }): string { | |
| /** | |
| * Structure representing matched CSS styles data. | |
| */ | |
| interface MatchedStylesData { | |
| inlineStyle?: { cssProperties?: Array<{ name: string; value: string }> }; | |
| matchedCSSRules?: Array<{ | |
| rule: { | |
| selectorList: { selectors: Array<{ text: string }> }; | |
| origin: string; | |
| style: { cssProperties: Array<{ name: string; value: string }> }; | |
| }; | |
| }>; | |
| inherited?: Array<{ | |
| matchedCSSRules?: Array<{ | |
| rule: { | |
| selectorList: { selectors: Array<{ text: string }> }; | |
| origin: string; | |
| style: { cssProperties: Array<{ name: string; value: string }> }; | |
| }; | |
| }>; | |
| }>; | |
| } | |
| formatMatchedStyles(matched: MatchedStylesData): string { |
No description provided.