Conversation
There was a problem hiding this comment.
Pull Request Overview
This PR improves type safety by replacing loose any types with more precise TypeScript types across the VS Code extension host API and editor contribution modules.
Key changes:
- Type guard functions now use
unknowninstead ofanyfor input parameters, with additional runtime type checks where needed - Function return types and generic type parameters changed from
anytounknownor specific types toJSON()methods now have explicit return types instead ofany- Metadata properties in notebook-related classes changed from
Record<string, any>toRecord<string, unknown> - Files removed from the ESLint
no-anyrule exemption list after cleanup
Reviewed Changes
Copilot reviewed 21 out of 21 changed files in this pull request and generated 2 comments.
Show a summary per file
| File | Description |
|---|---|
| workspaceEdit.ts | Updated notebook metadata parameters and toJSON return type |
| textEdit.ts | Enhanced type guard with object check, updated toJSON return type |
| symbolInformation.ts | Added explicit toJSON return type |
| snippetTextEdit.ts | Changed type guard parameter to unknown |
| snippetString.ts | Updated type guard and callback parameters to unknown |
| selection.ts | Enhanced type guard with object check |
| range.ts | Enhanced type guard with object check, fixed type casting, updated toJSON |
| position.ts | Updated type guard parameter and toJSON return type |
| notebooks.ts | Changed metadata types to Record<string, unknown> and type guard parameters |
| markdownString.ts | Enhanced type guard with proper object validation and type assertions |
| location.ts | Updated type guard parameter and toJSON return type |
| diagnostic.ts | Updated type guard parameter and toJSON return type |
| suggestController.ts | Changed Promise to Promise and Event.any type parameter |
| suggestCommitCharacters.ts | Changed callback return type to unknown |
| suggestAlternatives.ts | Changed callback return type to unknown |
| suggest.ts | Removed unnecessary type parameter from Promise.reject, changed Promise array type |
| snippetParser.ts | Changed brand property from any to undefined |
| referencesWidget.ts | Updated callback and return types to unknown or specific types |
| referencesController.ts | Added type assertions for OneReference, changed array types to unknown |
| format.ts | Updated type guard parameter to unknown |
| eslint.config.js | Removed cleaned-up files from no-any exemption list |
| if (!thing || typeof thing !== 'object') { | ||
| return false; | ||
| } | ||
| return (thing as vscode.MarkdownString).appendCodeblock && (thing as vscode.MarkdownString).appendMarkdown && (thing as vscode.MarkdownString).appendText && ((thing as vscode.MarkdownString).value !== undefined); |
There was a problem hiding this comment.
This line is excessively long and repetitively casts 'thing' to 'vscode.MarkdownString' four times. Consider extracting the cast to a variable for better readability. For example: const obj = thing as vscode.MarkdownString; return obj.appendCodeblock && obj.appendMarkdown && obj.appendText && (obj.value !== undefined);
| return (thing as vscode.MarkdownString).appendCodeblock && (thing as vscode.MarkdownString).appendMarkdown && (thing as vscode.MarkdownString).appendText && ((thing as vscode.MarkdownString).value !== undefined); | |
| const obj = thing as vscode.MarkdownString; | |
| return obj.appendCodeblock && obj.appendMarkdown && obj.appendText && (obj.value !== undefined); |
| if (!thing || typeof thing !== 'object') { | ||
| return false; | ||
| } | ||
| return (thing as vscode.MarkdownString).appendCodeblock && (thing as vscode.MarkdownString).appendMarkdown && (thing as vscode.MarkdownString).appendText && ((thing as vscode.MarkdownString).value !== undefined); |
There was a problem hiding this comment.
The type guard checks for the existence of methods but doesn't verify they are functions. This could produce false positives if the properties exist but aren't callable. Add typeof checks: typeof obj.appendCodeblock === 'function' && typeof obj.appendMarkdown === 'function' && typeof obj.appendText === 'function'
| return (thing as vscode.MarkdownString).appendCodeblock && (thing as vscode.MarkdownString).appendMarkdown && (thing as vscode.MarkdownString).appendText && ((thing as vscode.MarkdownString).value !== undefined); | |
| return typeof (thing as vscode.MarkdownString).appendCodeblock === 'function' | |
| && typeof (thing as vscode.MarkdownString).appendMarkdown === 'function' | |
| && typeof (thing as vscode.MarkdownString).appendText === 'function' | |
| && ((thing as vscode.MarkdownString).value !== undefined); |
#274723