From 0ce8e5c6c79cb53490158b96e1c22ffc2242c6b8 Mon Sep 17 00:00:00 2001 From: Johannes Rieken Date: Mon, 3 Nov 2025 14:45:30 +0100 Subject: [PATCH] cleanup any-usages (#274732) * cleanup any-usages https://github.com/microsoft/vscode/issues/274723 * ignore location for now --- eslint.config.js | 19 ------------ .../editor/contrib/format/browser/format.ts | 2 +- .../browser/peek/referencesController.ts | 14 ++++----- .../browser/peek/referencesWidget.ts | 8 ++--- .../contrib/snippet/browser/snippetParser.ts | 2 +- .../editor/contrib/suggest/browser/suggest.ts | 4 +-- .../suggest/browser/suggestAlternatives.ts | 4 +-- .../browser/suggestCommitCharacters.ts | 2 +- .../suggest/browser/suggestController.ts | 6 ++-- .../api/common/extHostTypes/diagnostic.ts | 4 +-- .../api/common/extHostTypes/location.ts | 2 +- .../api/common/extHostTypes/markdownString.ts | 7 +++-- .../api/common/extHostTypes/notebooks.ts | 29 +++++++++---------- .../api/common/extHostTypes/position.ts | 4 +-- .../api/common/extHostTypes/range.ts | 8 ++--- .../api/common/extHostTypes/selection.ts | 4 +-- .../api/common/extHostTypes/snippetString.ts | 8 ++--- .../common/extHostTypes/snippetTextEdit.ts | 2 +- .../common/extHostTypes/symbolInformation.ts | 2 +- .../api/common/extHostTypes/textEdit.ts | 6 ++-- .../api/common/extHostTypes/workspaceEdit.ts | 6 ++-- 21 files changed, 63 insertions(+), 80 deletions(-) diff --git a/eslint.config.js b/eslint.config.js index 3ce955187d0..69a9a692433 100644 --- a/eslint.config.js +++ b/eslint.config.js @@ -671,27 +671,19 @@ export default tseslint.config( 'src/vs/editor/contrib/find/browser/findWidgetSearchHistory.ts', 'src/vs/editor/contrib/find/browser/replaceWidgetHistory.ts', 'src/vs/editor/contrib/folding/browser/folding.ts', - 'src/vs/editor/contrib/format/browser/format.ts', 'src/vs/editor/contrib/gotoSymbol/browser/goToCommands.ts', 'src/vs/editor/contrib/gotoSymbol/browser/symbolNavigation.ts', 'src/vs/editor/contrib/hover/browser/hoverActions.ts', 'src/vs/editor/contrib/inlineCompletions/browser/structuredLogger.ts', 'src/vs/editor/contrib/inlineCompletions/browser/utils.ts', 'src/vs/editor/contrib/smartSelect/browser/smartSelect.ts', - 'src/vs/editor/contrib/snippet/browser/snippetParser.ts', 'src/vs/editor/contrib/stickyScroll/browser/stickyScrollModelProvider.ts', - 'src/vs/editor/contrib/suggest/browser/suggest.ts', - 'src/vs/editor/contrib/suggest/browser/suggestAlternatives.ts', - 'src/vs/editor/contrib/suggest/browser/suggestCommitCharacters.ts', - 'src/vs/editor/contrib/suggest/browser/suggestController.ts', 'src/vs/editor/contrib/unicodeHighlighter/browser/unicodeHighlighter.ts', 'src/vs/editor/contrib/wordHighlighter/browser/wordHighlighter.ts', 'src/vs/editor/standalone/common/monarch/monarchCommon.ts', 'src/vs/editor/standalone/common/monarch/monarchCompile.ts', 'src/vs/editor/standalone/common/monarch/monarchLexer.ts', 'src/vs/editor/standalone/common/monarch/monarchTypes.ts', - 'src/vs/editor/contrib/gotoSymbol/browser/peek/referencesController.ts', - 'src/vs/editor/contrib/gotoSymbol/browser/peek/referencesWidget.ts', 'src/vs/editor/contrib/inlineCompletions/browser/controller/commands.ts', 'src/vs/editor/contrib/inlineCompletions/browser/model/inlineCompletionsModel.ts', 'src/vs/editor/contrib/inlineCompletions/browser/model/typingSpeed.ts', @@ -741,19 +733,8 @@ export default tseslint.config( 'src/vs/workbench/api/common/extHostTreeViews.ts', 'src/vs/workbench/api/common/extHostTypeConverters.ts', 'src/vs/workbench/api/common/extHostTypes.ts', - 'src/vs/workbench/api/common/extHostTypes/diagnostic.ts', 'src/vs/workbench/api/common/extHostTypes/es5ClassCompat.ts', 'src/vs/workbench/api/common/extHostTypes/location.ts', - 'src/vs/workbench/api/common/extHostTypes/markdownString.ts', - 'src/vs/workbench/api/common/extHostTypes/notebooks.ts', - 'src/vs/workbench/api/common/extHostTypes/position.ts', - 'src/vs/workbench/api/common/extHostTypes/range.ts', - 'src/vs/workbench/api/common/extHostTypes/selection.ts', - 'src/vs/workbench/api/common/extHostTypes/snippetString.ts', - 'src/vs/workbench/api/common/extHostTypes/snippetTextEdit.ts', - 'src/vs/workbench/api/common/extHostTypes/symbolInformation.ts', - 'src/vs/workbench/api/common/extHostTypes/textEdit.ts', - 'src/vs/workbench/api/common/extHostTypes/workspaceEdit.ts', 'src/vs/workbench/api/common/extHostWebview.ts', 'src/vs/workbench/api/common/extHostWebviewMessaging.ts', 'src/vs/workbench/api/common/extHostWebviewPanels.ts', diff --git a/src/vs/editor/contrib/format/browser/format.ts b/src/vs/editor/contrib/format/browser/format.ts index 858b4d201d7..2e5842846d5 100644 --- a/src/vs/editor/contrib/format/browser/format.ts +++ b/src/vs/editor/contrib/format/browser/format.ts @@ -460,7 +460,7 @@ export function getOnTypeFormattingEdits( }); } -function isFormattingOptions(obj: any): obj is FormattingOptions { +function isFormattingOptions(obj: unknown): obj is FormattingOptions { const candidate = obj as FormattingOptions | undefined; return !!candidate && typeof candidate === 'object' && typeof candidate.tabSize === 'number' && typeof candidate.insertSpaces === 'boolean'; diff --git a/src/vs/editor/contrib/gotoSymbol/browser/peek/referencesController.ts b/src/vs/editor/contrib/gotoSymbol/browser/peek/referencesController.ts index 48ba268a699..de9034994fc 100644 --- a/src/vs/editor/contrib/gotoSymbol/browser/peek/referencesController.ts +++ b/src/vs/editor/contrib/gotoSymbol/browser/peek/referencesController.ts @@ -245,7 +245,7 @@ export abstract class ReferencesController implements IEditorContribution { this._requestIdPool += 1; // Cancel pending requests } - private _gotoReference(ref: Location, pinned: boolean): Promise { + private _gotoReference(ref: Location, pinned: boolean): Promise { this._widget?.hide(); this._ignoreModelChangeEvent = true; @@ -397,9 +397,9 @@ KeybindingsRegistry.registerCommandAndKeybindingRule({ when: ContextKeyExpr.and(ctxReferenceSearchVisible, WorkbenchListFocusContextKey, WorkbenchTreeElementCanCollapse.negate(), WorkbenchTreeElementCanExpand.negate()), handler(accessor: ServicesAccessor) { const listService = accessor.get(IListService); - const focus = listService.lastFocusedList?.getFocus(); + const focus = listService.lastFocusedList?.getFocus(); if (Array.isArray(focus) && focus[0] instanceof OneReference) { - withController(accessor, controller => controller.revealReference(focus[0])); + withController(accessor, controller => controller.revealReference(focus[0] as OneReference)); } } }); @@ -414,17 +414,17 @@ KeybindingsRegistry.registerCommandAndKeybindingRule({ when: ContextKeyExpr.and(ctxReferenceSearchVisible, WorkbenchListFocusContextKey, WorkbenchTreeElementCanCollapse.negate(), WorkbenchTreeElementCanExpand.negate()), handler(accessor: ServicesAccessor) { const listService = accessor.get(IListService); - const focus = listService.lastFocusedList?.getFocus(); + const focus = listService.lastFocusedList?.getFocus(); if (Array.isArray(focus) && focus[0] instanceof OneReference) { - withController(accessor, controller => controller.openReference(focus[0], true, true)); + withController(accessor, controller => controller.openReference(focus[0] as OneReference, true, true)); } } }); CommandsRegistry.registerCommand('openReference', (accessor) => { const listService = accessor.get(IListService); - const focus = listService.lastFocusedList?.getFocus(); + const focus = listService.lastFocusedList?.getFocus(); if (Array.isArray(focus) && focus[0] instanceof OneReference) { - withController(accessor, controller => controller.openReference(focus[0], false, true)); + withController(accessor, controller => controller.openReference(focus[0] as OneReference, false, true)); } }); diff --git a/src/vs/editor/contrib/gotoSymbol/browser/peek/referencesWidget.ts b/src/vs/editor/contrib/gotoSymbol/browser/peek/referencesWidget.ts index 9581b5cf6ff..f7330a59080 100644 --- a/src/vs/editor/contrib/gotoSymbol/browser/peek/referencesWidget.ts +++ b/src/vs/editor/contrib/gotoSymbol/browser/peek/referencesWidget.ts @@ -432,7 +432,7 @@ export class ReferenceWidget extends peekView.PeekViewWidget { }, undefined)); // listen on selection and focus - const onEvent = (element: any, kind: 'show' | 'goto' | 'side') => { + const onEvent = (element: TreeElement | undefined, kind: 'show' | 'goto' | 'side') => { if (element instanceof OneReference) { if (kind === 'show') { this._revealReference(element, false); @@ -467,7 +467,7 @@ export class ReferenceWidget extends peekView.PeekViewWidget { this._splitView.resizeView(0, widthInPixel * this.layoutData.ratio); } - setSelection(selection: OneReference): Promise { + setSelection(selection: OneReference): Promise { return this._revealReference(selection, true).then(() => { if (!this._model) { // disposed @@ -479,7 +479,7 @@ export class ReferenceWidget extends peekView.PeekViewWidget { }); } - setModel(newModel: ReferencesModel | undefined): Promise { + setModel(newModel: ReferencesModel | undefined): Promise { // clean up this._disposeOnNewModel.clear(); this._model = newModel; @@ -489,7 +489,7 @@ export class ReferenceWidget extends peekView.PeekViewWidget { return Promise.resolve(); } - private _onNewModel(): Promise { + private _onNewModel(): Promise { if (!this._model) { return Promise.resolve(undefined); } diff --git a/src/vs/editor/contrib/snippet/browser/snippetParser.ts b/src/vs/editor/contrib/snippet/browser/snippetParser.ts index 6005f88c65f..f045cf0cef9 100644 --- a/src/vs/editor/contrib/snippet/browser/snippetParser.ts +++ b/src/vs/editor/contrib/snippet/browser/snippetParser.ts @@ -129,7 +129,7 @@ export class Scanner { export abstract class Marker { - readonly _markerBrand: any; + readonly _markerBrand: undefined; public parent!: Marker; protected _children: Marker[] = []; diff --git a/src/vs/editor/contrib/suggest/browser/suggest.ts b/src/vs/editor/contrib/suggest/browser/suggest.ts index c63d3bb81b1..06e412ef142 100644 --- a/src/vs/editor/contrib/suggest/browser/suggest.ts +++ b/src/vs/editor/contrib/suggest/browser/suggest.ts @@ -323,7 +323,7 @@ export async function provideSuggestionItems( if (token.isCancellationRequested) { disposables.dispose(); - return Promise.reject(new CancellationError()); + return Promise.reject(new CancellationError()); } return new CompletionItemModel( @@ -402,7 +402,7 @@ CommandsRegistry.registerCommand('_executeCompletionItemProvider', async (access suggestions: [] }; - const resolving: Promise[] = []; + const resolving: Promise[] = []; const actualPosition = ref.object.textEditorModel.validatePosition(position); const completions = await provideSuggestionItems(completionProvider, ref.object.textEditorModel, actualPosition, undefined, { triggerCharacter: triggerCharacter ?? undefined, triggerKind: triggerCharacter ? languages.CompletionTriggerKind.TriggerCharacter : languages.CompletionTriggerKind.Invoke }); for (const item of completions.items) { diff --git a/src/vs/editor/contrib/suggest/browser/suggestAlternatives.ts b/src/vs/editor/contrib/suggest/browser/suggestAlternatives.ts index f108e89874d..0ce7dd0a708 100644 --- a/src/vs/editor/contrib/suggest/browser/suggestAlternatives.ts +++ b/src/vs/editor/contrib/suggest/browser/suggestAlternatives.ts @@ -17,7 +17,7 @@ export class SuggestAlternatives { private _index: number = 0; private _model: CompletionModel | undefined; - private _acceptNext: ((selected: ISelectedSuggestion) => any) | undefined; + private _acceptNext: ((selected: ISelectedSuggestion) => unknown) | undefined; private _listener: IDisposable | undefined; private _ignore: boolean | undefined; @@ -40,7 +40,7 @@ export class SuggestAlternatives { this._ignore = false; } - set({ model, index }: ISelectedSuggestion, acceptNext: (selected: ISelectedSuggestion) => any): void { + set({ model, index }: ISelectedSuggestion, acceptNext: (selected: ISelectedSuggestion) => unknown): void { // no suggestions -> nothing to do if (model.items.length === 0) { diff --git a/src/vs/editor/contrib/suggest/browser/suggestCommitCharacters.ts b/src/vs/editor/contrib/suggest/browser/suggestCommitCharacters.ts index fb2eb635ca2..7efaefec302 100644 --- a/src/vs/editor/contrib/suggest/browser/suggestCommitCharacters.ts +++ b/src/vs/editor/contrib/suggest/browser/suggestCommitCharacters.ts @@ -20,7 +20,7 @@ export class CommitCharacterController { readonly item: ISelectedSuggestion; }; - constructor(editor: ICodeEditor, widget: SuggestWidget, model: SuggestModel, accept: (selected: ISelectedSuggestion) => any) { + constructor(editor: ICodeEditor, widget: SuggestWidget, model: SuggestModel, accept: (selected: ISelectedSuggestion) => unknown) { this._disposables.add(model.onDidSuggest(e => { if (e.completionModel.items.length === 0) { diff --git a/src/vs/editor/contrib/suggest/browser/suggestController.ts b/src/vs/editor/contrib/suggest/browser/suggestController.ts index adf4a5e52d2..95639548d0c 100644 --- a/src/vs/editor/contrib/suggest/browser/suggestController.ts +++ b/src/vs/editor/contrib/suggest/browser/suggestController.ts @@ -347,7 +347,7 @@ export class SuggestController implements IEditorContribution { const { item } = event; // - const tasks: Promise[] = []; + const tasks: Promise[] = []; const cts = new CancellationTokenSource(); // pushing undo stops *before* additional text edits and @@ -662,7 +662,7 @@ export class SuggestController implements IEditorContribution { // wait for trigger because only then the cancel-event is trustworthy const listener: IDisposable[] = []; - Event.any(this.model.onDidTrigger, this.model.onDidCancel)(() => { + Event.any(this.model.onDidTrigger, this.model.onDidCancel)(() => { // retrigger or cancel -> try to type default text dispose(listener); fallback(); @@ -829,7 +829,7 @@ export class TriggerSuggestAction extends EditorAction { }); } - run(_accessor: ServicesAccessor, editor: ICodeEditor, args: any): void { + run(_accessor: ServicesAccessor, editor: ICodeEditor, args: unknown): void { const controller = SuggestController.get(editor); if (!controller) { diff --git a/src/vs/workbench/api/common/extHostTypes/diagnostic.ts b/src/vs/workbench/api/common/extHostTypes/diagnostic.ts index 486e383fcff..9a5b0e2bcdb 100644 --- a/src/vs/workbench/api/common/extHostTypes/diagnostic.ts +++ b/src/vs/workbench/api/common/extHostTypes/diagnostic.ts @@ -24,7 +24,7 @@ export enum DiagnosticSeverity { @es5ClassCompat export class DiagnosticRelatedInformation { - static is(thing: any): thing is DiagnosticRelatedInformation { + static is(thing: unknown): thing is DiagnosticRelatedInformation { if (!thing) { return false; } @@ -78,7 +78,7 @@ export class Diagnostic { this.severity = severity; } - toJSON(): any { + toJSON(): { severity: string; message: string; range: Range; source?: string; code?: string | number } { return { severity: DiagnosticSeverity[this.severity], message: this.message, diff --git a/src/vs/workbench/api/common/extHostTypes/location.ts b/src/vs/workbench/api/common/extHostTypes/location.ts index 7fb90d61e01..27d6a7e3deb 100644 --- a/src/vs/workbench/api/common/extHostTypes/location.ts +++ b/src/vs/workbench/api/common/extHostTypes/location.ts @@ -12,7 +12,7 @@ import { Range } from './range.js'; @es5ClassCompat export class Location { - static isLocation(thing: any): thing is vscode.Location { + static isLocation(thing: unknown): thing is vscode.Location { if (thing instanceof Location) { return true; } diff --git a/src/vs/workbench/api/common/extHostTypes/markdownString.ts b/src/vs/workbench/api/common/extHostTypes/markdownString.ts index b0097e834a4..c7840b9f74a 100644 --- a/src/vs/workbench/api/common/extHostTypes/markdownString.ts +++ b/src/vs/workbench/api/common/extHostTypes/markdownString.ts @@ -14,11 +14,14 @@ export class MarkdownString implements vscode.MarkdownString { readonly #delegate: BaseMarkdownString; - static isMarkdownString(thing: any): thing is vscode.MarkdownString { + static isMarkdownString(thing: unknown): thing is vscode.MarkdownString { if (thing instanceof MarkdownString) { return true; } - return thing && thing.appendCodeblock && thing.appendMarkdown && thing.appendText && (thing.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); } constructor(value?: string, supportThemeIcons: boolean = false) { diff --git a/src/vs/workbench/api/common/extHostTypes/notebooks.ts b/src/vs/workbench/api/common/extHostTypes/notebooks.ts index 70699af399e..3c8e9060223 100644 --- a/src/vs/workbench/api/common/extHostTypes/notebooks.ts +++ b/src/vs/workbench/api/common/extHostTypes/notebooks.ts @@ -17,7 +17,7 @@ export enum NotebookCellKind { } export class NotebookRange { - static isNotebookRange(thing: any): thing is vscode.NotebookRange { + static isNotebookRange(thing: unknown): thing is vscode.NotebookRange { if (thing instanceof NotebookRange) { return true; } @@ -104,10 +104,10 @@ export class NotebookCellData { languageId: string; mime?: string; outputs?: vscode.NotebookCellOutput[]; - metadata?: Record; + metadata?: Record; executionSummary?: vscode.NotebookCellExecutionSummary; - constructor(kind: NotebookCellKind, value: string, languageId: string, mime?: string, outputs?: vscode.NotebookCellOutput[], metadata?: Record, executionSummary?: vscode.NotebookCellExecutionSummary) { + constructor(kind: NotebookCellKind, value: string, languageId: string, mime?: string, outputs?: vscode.NotebookCellOutput[], metadata?: Record, executionSummary?: vscode.NotebookCellExecutionSummary) { this.kind = kind; this.value = value; this.languageId = languageId; @@ -123,7 +123,7 @@ export class NotebookCellData { export class NotebookData { cells: NotebookCellData[]; - metadata?: { [key: string]: any }; + metadata?: { [key: string]: unknown }; constructor(cells: NotebookCellData[]) { this.cells = cells; @@ -133,7 +133,7 @@ export class NotebookData { @es5ClassCompat export class NotebookEdit implements vscode.NotebookEdit { - static isNotebookCellEdit(thing: any): thing is NotebookEdit { + static isNotebookCellEdit(thing: unknown): thing is NotebookEdit { if (thing instanceof NotebookEdit) { return true; } @@ -156,13 +156,13 @@ export class NotebookEdit implements vscode.NotebookEdit { return new NotebookEdit(range, []); } - static updateCellMetadata(index: number, newMetadata: { [key: string]: any }): NotebookEdit { + static updateCellMetadata(index: number, newMetadata: { [key: string]: unknown }): NotebookEdit { const edit = new NotebookEdit(new NotebookRange(index, index), []); edit.newCellMetadata = newMetadata; return edit; } - static updateNotebookMetadata(newMetadata: { [key: string]: any }): NotebookEdit { + static updateNotebookMetadata(newMetadata: { [key: string]: unknown }): NotebookEdit { const edit = new NotebookEdit(new NotebookRange(0, 0), []); edit.newNotebookMetadata = newMetadata; return edit; @@ -170,8 +170,8 @@ export class NotebookEdit implements vscode.NotebookEdit { range: NotebookRange; newCells: NotebookCellData[]; - newCellMetadata?: { [key: string]: any }; - newNotebookMetadata?: { [key: string]: any }; + newCellMetadata?: { [key: string]: unknown }; + newNotebookMetadata?: { [key: string]: unknown }; constructor(range: NotebookRange, newCells: NotebookCellData[]) { this.range = range; @@ -220,7 +220,7 @@ export class NotebookCellOutputItem { return new NotebookCellOutputItem(bytes, mime); } - static json(value: any, mime: string = 'text/x-json'): NotebookCellOutputItem { + static json(value: unknown, mime: string = 'text/x-json'): NotebookCellOutputItem { const rawStr = JSON.stringify(value, undefined, '\t'); return NotebookCellOutputItem.text(rawStr, mime); } @@ -239,7 +239,7 @@ export class NotebookCellOutputItem { export class NotebookCellOutput { - static isNotebookCellOutput(candidate: any): candidate is vscode.NotebookCellOutput { + static isNotebookCellOutput(candidate: unknown): candidate is vscode.NotebookCellOutput { if (candidate instanceof NotebookCellOutput) { return true; } @@ -274,12 +274,12 @@ export class NotebookCellOutput { id: string; items: NotebookCellOutputItem[]; - metadata?: Record; + metadata?: Record; constructor( items: NotebookCellOutputItem[], - idOrMetadata?: string | Record, - metadata?: Record + idOrMetadata?: string | Record, + metadata?: Record ) { this.items = NotebookCellOutput.ensureUniqueMimeTypes(items, true); if (typeof idOrMetadata === 'string') { @@ -291,4 +291,3 @@ export class NotebookCellOutput { } } } - diff --git a/src/vs/workbench/api/common/extHostTypes/position.ts b/src/vs/workbench/api/common/extHostTypes/position.ts index 63a7b1d31af..08145ff57f9 100644 --- a/src/vs/workbench/api/common/extHostTypes/position.ts +++ b/src/vs/workbench/api/common/extHostTypes/position.ts @@ -38,7 +38,7 @@ export class Position { return result; } - static isPosition(other: any): other is Position { + static isPosition(other: unknown): other is Position { if (!other) { return false; } @@ -183,7 +183,7 @@ export class Position { return new Position(line, character); } - toJSON(): any { + toJSON(): { line: number; character: number } { return { line: this.line, character: this.character }; } diff --git a/src/vs/workbench/api/common/extHostTypes/range.ts b/src/vs/workbench/api/common/extHostTypes/range.ts index 3bbf1f2db04..10f03baf8e6 100644 --- a/src/vs/workbench/api/common/extHostTypes/range.ts +++ b/src/vs/workbench/api/common/extHostTypes/range.ts @@ -11,15 +11,15 @@ import { Position } from './position.js'; @es5ClassCompat export class Range { - static isRange(thing: any): thing is vscode.Range { + static isRange(thing: unknown): thing is vscode.Range { if (thing instanceof Range) { return true; } - if (!thing) { + if (!thing || typeof thing !== 'object') { return false; } return Position.isPosition((thing).start) - && Position.isPosition((thing.end)); + && Position.isPosition((thing).end); } static of(obj: vscode.Range): Range { @@ -149,7 +149,7 @@ export class Range { return new Range(start, end); } - toJSON(): any { + toJSON(): unknown { return [this.start, this.end]; } diff --git a/src/vs/workbench/api/common/extHostTypes/selection.ts b/src/vs/workbench/api/common/extHostTypes/selection.ts index 32de7de7543..18b14f3233b 100644 --- a/src/vs/workbench/api/common/extHostTypes/selection.ts +++ b/src/vs/workbench/api/common/extHostTypes/selection.ts @@ -11,11 +11,11 @@ import { getDebugDescriptionOfRange, Range } from './range.js'; @es5ClassCompat export class Selection extends Range { - static isSelection(thing: any): thing is Selection { + static isSelection(thing: unknown): thing is Selection { if (thing instanceof Selection) { return true; } - if (!thing) { + if (!thing || typeof thing !== 'object') { return false; } return Range.isRange(thing) diff --git a/src/vs/workbench/api/common/extHostTypes/snippetString.ts b/src/vs/workbench/api/common/extHostTypes/snippetString.ts index f1c083ce373..49776d0e01b 100644 --- a/src/vs/workbench/api/common/extHostTypes/snippetString.ts +++ b/src/vs/workbench/api/common/extHostTypes/snippetString.ts @@ -8,11 +8,11 @@ import { es5ClassCompat } from './es5ClassCompat.js'; @es5ClassCompat export class SnippetString { - static isSnippetString(thing: any): thing is SnippetString { + static isSnippetString(thing: unknown): thing is SnippetString { if (thing instanceof SnippetString) { return true; } - if (!thing) { + if (!thing || typeof thing !== 'object') { return false; } return typeof (thing).value === 'string'; @@ -41,7 +41,7 @@ export class SnippetString { return this; } - appendPlaceholder(value: string | ((snippet: SnippetString) => any), number: number = this._tabstop++): SnippetString { + appendPlaceholder(value: string | ((snippet: SnippetString) => unknown), number: number = this._tabstop++): SnippetString { if (typeof value === 'function') { const nested = new SnippetString(); @@ -74,7 +74,7 @@ export class SnippetString { return this; } - appendVariable(name: string, defaultValue?: string | ((snippet: SnippetString) => any)): SnippetString { + appendVariable(name: string, defaultValue?: string | ((snippet: SnippetString) => unknown)): SnippetString { if (typeof defaultValue === 'function') { const nested = new SnippetString(); diff --git a/src/vs/workbench/api/common/extHostTypes/snippetTextEdit.ts b/src/vs/workbench/api/common/extHostTypes/snippetTextEdit.ts index a9dc25b57b4..8b1eb6c1fb1 100644 --- a/src/vs/workbench/api/common/extHostTypes/snippetTextEdit.ts +++ b/src/vs/workbench/api/common/extHostTypes/snippetTextEdit.ts @@ -10,7 +10,7 @@ import { Range } from './range.js'; export class SnippetTextEdit implements vscode.SnippetTextEdit { - static isSnippetTextEdit(thing: any): thing is SnippetTextEdit { + static isSnippetTextEdit(thing: unknown): thing is SnippetTextEdit { if (thing instanceof SnippetTextEdit) { return true; } diff --git a/src/vs/workbench/api/common/extHostTypes/symbolInformation.ts b/src/vs/workbench/api/common/extHostTypes/symbolInformation.ts index b56fbf7daff..1df3f22edc3 100644 --- a/src/vs/workbench/api/common/extHostTypes/symbolInformation.ts +++ b/src/vs/workbench/api/common/extHostTypes/symbolInformation.ts @@ -76,7 +76,7 @@ export class SymbolInformation { SymbolInformation.validate(this); } - toJSON(): any { + toJSON(): { name: string; kind: string; location: Location; containerName: string | undefined } { return { name: this.name, kind: SymbolKind[this.kind], diff --git a/src/vs/workbench/api/common/extHostTypes/textEdit.ts b/src/vs/workbench/api/common/extHostTypes/textEdit.ts index 565f09c45e0..5324b6d6b64 100644 --- a/src/vs/workbench/api/common/extHostTypes/textEdit.ts +++ b/src/vs/workbench/api/common/extHostTypes/textEdit.ts @@ -16,11 +16,11 @@ export enum EndOfLine { @es5ClassCompat export class TextEdit { - static isTextEdit(thing: any): thing is TextEdit { + static isTextEdit(thing: unknown): thing is TextEdit { if (thing instanceof TextEdit) { return true; } - if (!thing) { + if (!thing || typeof thing !== 'object') { return false; } return Range.isRange((thing)) @@ -87,7 +87,7 @@ export class TextEdit { this._newText = newText; } - toJSON(): any { + toJSON(): { range: Range; newText: string; newEol: EndOfLine | undefined } { return { range: this.range, newText: this.newText, diff --git a/src/vs/workbench/api/common/extHostTypes/workspaceEdit.ts b/src/vs/workbench/api/common/extHostTypes/workspaceEdit.ts index 7104fcb3eb8..ec47f455b7e 100644 --- a/src/vs/workbench/api/common/extHostTypes/workspaceEdit.ts +++ b/src/vs/workbench/api/common/extHostTypes/workspaceEdit.ts @@ -97,7 +97,7 @@ export class WorkspaceEdit implements vscode.WorkspaceEdit { } // --- notebook - private replaceNotebookMetadata(uri: URI, value: Record, metadata?: vscode.WorkspaceEditEntryMetadata): void { + private replaceNotebookMetadata(uri: URI, value: Record, metadata?: vscode.WorkspaceEditEntryMetadata): void { this._edits.push({ _type: FileEditType.Cell, metadata, uri, edit: { editType: CellEditType.DocumentMetadata, metadata: value } }); } @@ -110,7 +110,7 @@ export class WorkspaceEdit implements vscode.WorkspaceEdit { } } - private replaceNotebookCellMetadata(uri: URI, index: number, cellMetadata: Record, metadata?: vscode.WorkspaceEditEntryMetadata): void { + private replaceNotebookCellMetadata(uri: URI, index: number, cellMetadata: Record, metadata?: vscode.WorkspaceEditEntryMetadata): void { this._edits.push({ _type: FileEditType.Cell, metadata, uri, edit: { editType: CellEditType.Metadata, index, metadata: cellMetadata } }); } @@ -215,7 +215,7 @@ export class WorkspaceEdit implements vscode.WorkspaceEdit { return this.entries().length; } - toJSON(): any { + toJSON(): [URI, TextEdit[]][] { return this.entries(); } }