Skip to content
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

Clean up any type uses #11490

Merged
merged 1 commit into from
Aug 4, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 2 additions & 4 deletions dev-packages/ovsx-client/src/ovsx-types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -164,10 +164,8 @@ export interface VSXResponseError extends Error {
}

export namespace VSXResponseError {
// eslint-disable-next-line @typescript-eslint/no-explicit-any
export function is(error: any): error is VSXResponseError {
return !!error && typeof error === 'object'
&& 'statusCode' in error && typeof error['statusCode'] === 'number';
export function is(error: unknown): error is VSXResponseError {
return !!error && typeof error === 'object' && typeof (error as VSXResponseError).statusCode === 'number';
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,8 @@ export interface BulkEditNodeSelection {
bulkEdit: ResourceFileEdit | ResourceTextEdit;
}
export namespace BulkEditNodeSelection {
export function is(arg: Object | undefined): arg is BulkEditNodeSelection {
return typeof arg === 'object' && ('bulkEdit' in arg);
export function is(arg: unknown): arg is BulkEditNodeSelection {
return !!arg && typeof arg === 'object' && ('bulkEdit' in arg);
}

export class CommandHandler extends SelectionCommandHandler<BulkEditNodeSelection> {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,7 @@ export interface BulkEditInfoNode extends UriSelection, SelectableTreeNode, Expa
fileContents?: string;
}
export namespace BulkEditInfoNode {
export function is(node: Object | undefined): node is BulkEditInfoNode {
export function is(node: unknown): node is BulkEditInfoNode {
return ExpandableTreeNode.is(node) && UriSelection.is(node) && 'fileContents' in node;
}
}
7 changes: 1 addition & 6 deletions packages/core/src/browser/decorations-service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
// *****************************************************************************

import { injectable } from 'inversify';
import { isThenable } from '../common/promise-util';
import { CancellationToken, CancellationTokenSource, Disposable, Emitter, Event } from '../common';
import { TernarySearchTree } from '../common/ternary-search-tree';
import URI from '../common/uri';
Expand Down Expand Up @@ -157,12 +158,6 @@ class DecorationProviderWrapper {
this.data.set(uri, request);
return undefined;
}

// eslint-disable-next-line @typescript-eslint/no-explicit-any
function isThenable<T>(obj: any): obj is Promise<T> {
// eslint-disable-next-line @typescript-eslint/no-explicit-any
return obj && typeof (<Promise<any>>obj).then === 'function';
}
}

private keepItem(uri: URI, data: Decoration | undefined): Decoration | undefined {
Expand Down
5 changes: 2 additions & 3 deletions packages/core/src/browser/label-provider.ts
Original file line number Diff line number Diff line change
Expand Up @@ -93,9 +93,8 @@ export interface URIIconReference {
uri?: URI
}
export namespace URIIconReference {
// eslint-disable-next-line @typescript-eslint/no-explicit-any
export function is(element: any | undefined): element is URIIconReference {
return !!element && typeof element === 'object' && 'kind' in element && element['kind'] === 'uriIconReference';
export function is(element: unknown): element is URIIconReference {
return !!element && typeof element === 'object' && 'kind' in element && (element as URIIconReference).kind === 'uriIconReference';
}
export function create(id: URIIconReference['id'], uri?: URI): URIIconReference {
return { kind: 'uriIconReference', id, uri };
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,6 @@
// SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0
// *****************************************************************************

/* eslint-disable @typescript-eslint/no-explicit-any */

import { inject, injectable } from 'inversify';
import { Menu } from '../widgets';
import { ContextMenuAccess, ContextMenuRenderer, coordinateFromAnchor, RenderContextMenuOptions } from '../context-menu-renderer';
Expand Down
11 changes: 5 additions & 6 deletions packages/core/src/browser/navigatable-types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,14 +33,14 @@ export interface Navigatable {
}

export namespace Navigatable {
export function is(arg: Object | undefined): arg is Navigatable {
return !!arg && 'getResourceUri' in arg && 'createMoveToUri' in arg;
export function is(arg: unknown): arg is Navigatable {
return !!arg && typeof arg === 'object' && 'getResourceUri' in arg && 'createMoveToUri' in arg;
}
}

export type NavigatableWidget = BaseWidget & Navigatable;
export namespace NavigatableWidget {
export function is(arg: Object | undefined): arg is NavigatableWidget {
export function is(arg: unknown): arg is NavigatableWidget {
return arg instanceof BaseWidget && Navigatable.is(arg);
}
export function* getAffected<T extends Widget>(
Expand Down Expand Up @@ -76,8 +76,7 @@ export interface NavigatableWidgetOptions {
counter?: number,
}
export namespace NavigatableWidgetOptions {
export function is(arg: Object | undefined): arg is NavigatableWidgetOptions {
// eslint-disable-next-line @typescript-eslint/no-explicit-any
return !!arg && 'kind' in arg && (arg as any).kind === 'navigatable';
export function is(arg: unknown): arg is NavigatableWidgetOptions {
return !!arg && typeof arg === 'object' && 'kind' in arg && (arg as NavigatableWidgetOptions).kind === 'navigatable';
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,7 @@ export class InjectablePreferenceProxy<T extends Record<string, JSONValue>> impl
if (this.schema && (this.isFlat || !property.includes('.')) && this.schema.properties[preferenceName]) {
const { overrideIdentifier } = this;
const toGet = overrideIdentifier ? this.preferences.overridePreferenceName({ overrideIdentifier, preferenceName }) : preferenceName;
return this.getValue(toGet as keyof T & string, undefined as any); // eslint-disable-line @typescript-eslint/no-explicit-any
return this.getValue(toGet as keyof T & string, undefined!);
}
switch (property) {
case 'onPreferenceChanged':
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,7 @@ export interface OverridePreferenceName {
overrideIdentifier: string
}
export namespace OverridePreferenceName {
// eslint-disable-next-line @typescript-eslint/no-explicit-any
export function is(arg: any): arg is OverridePreferenceName {
export function is(arg: unknown): arg is OverridePreferenceName {
return !!arg && typeof arg === 'object' && 'preferenceName' in arg && 'overrideIdentifier' in arg;
}
}
Expand All @@ -37,8 +36,7 @@ export const getOverridePattern = (identifier: string) => `\\[(${identifier})\\]
export class PreferenceLanguageOverrideService {
protected readonly overrideIdentifiers = new Set<string>();

// eslint-disable-next-line @typescript-eslint/no-explicit-any
testOverrideValue(name: string, value: any): value is PreferenceSchemaProperties {
testOverrideValue(name: string, value: unknown): value is PreferenceSchemaProperties {
return PreferenceSchemaProperties.is(value) && OVERRIDE_PROPERTY_PATTERN.test(name);
}

Expand Down
24 changes: 9 additions & 15 deletions packages/core/src/browser/saveable.ts
Original file line number Diff line number Diff line change
Expand Up @@ -59,16 +59,13 @@ export namespace Saveable {
}

export type Snapshot = { value: string } | { read(): string | null };
// eslint-disable-next-line @typescript-eslint/no-explicit-any
export function isSource(arg: any): arg is SaveableSource {
return !!arg && ('saveable' in arg) && is(arg.saveable);
export function isSource(arg: unknown): arg is SaveableSource {
return typeof arg === 'object' && !!arg && is((arg as SaveableSource).saveable);
}
// eslint-disable-next-line @typescript-eslint/no-explicit-any
export function is(arg: any): arg is Saveable {
return !!arg && ('dirty' in arg) && ('onDirtyChanged' in arg);
export function is(arg: unknown): arg is Saveable {
return typeof arg === 'object' && !!arg && 'dirty' in arg && 'onDirtyChanged' in arg;
}
// eslint-disable-next-line @typescript-eslint/no-explicit-any
export function get(arg: any): Saveable | undefined {
export function get(arg: unknown): Saveable | undefined {
if (is(arg)) {
return arg;
}
Expand All @@ -77,20 +74,17 @@ export namespace Saveable {
}
return undefined;
}
// eslint-disable-next-line @typescript-eslint/no-explicit-any
export function getDirty(arg: any): Saveable | undefined {
export function getDirty(arg: unknown): Saveable | undefined {
const saveable = get(arg);
if (saveable && saveable.dirty) {
return saveable;
}
return undefined;
}
// eslint-disable-next-line @typescript-eslint/no-explicit-any
export function isDirty(arg: any): boolean {
export function isDirty(arg: unknown): boolean {
return !!getDirty(arg);
}
// eslint-disable-next-line @typescript-eslint/no-explicit-any
export async function save(arg: any, options?: SaveOptions): Promise<void> {
export async function save(arg: unknown, options?: SaveOptions): Promise<void> {
const saveable = get(arg);
if (saveable) {
await saveable.save(options);
Expand Down Expand Up @@ -229,7 +223,7 @@ export namespace SaveableWidget {
return !!widget && 'closeWithoutSaving' in widget;
}
export function getDirty<T extends Widget>(widgets: Iterable<T>): IterableIterator<SaveableWidget & T> {
return get(widgets, Saveable.isDirty);
return get<T>(widgets, Saveable.isDirty);
}
export function* get<T extends Widget>(
widgets: Iterable<T>,
Expand Down
13 changes: 6 additions & 7 deletions packages/core/src/browser/shell/application-shell.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1934,10 +1934,9 @@ export namespace ApplicationShell {
return area === 'left' || area === 'right' || area === 'bottom';
}

// eslint-disable-next-line @typescript-eslint/no-explicit-any
export function isValidArea(area?: any): area is ApplicationShell.Area {
export function isValidArea(area?: unknown): area is ApplicationShell.Area {
const areas = ['main', 'top', 'left', 'right', 'bottom'];
return (area !== undefined && typeof area === 'string' && areas.includes(area));
return typeof area === 'string' && areas.includes(area);
}

/**
Expand Down Expand Up @@ -1981,8 +1980,8 @@ export namespace ApplicationShell {
* Whether a widget should be opened to the side tab bar relatively to the reference widget.
*/
export type OpenToSideMode = 'open-to-left' | 'open-to-right';
// eslint-disable-next-line @typescript-eslint/no-explicit-any
export function isOpenToSideMode(mode: OpenToSideMode | any): mode is OpenToSideMode {

export function isOpenToSideMode(mode: unknown): mode is OpenToSideMode {
return mode === 'open-to-left' || mode === 'open-to-right';
}

Expand Down Expand Up @@ -2060,8 +2059,8 @@ export namespace ApplicationShell {
}

export namespace TrackableWidgetProvider {
export function is(widget: object | undefined): widget is TrackableWidgetProvider {
return !!widget && 'getTrackableWidgets' in widget;
export function is(widget: unknown): widget is TrackableWidgetProvider {
return !!widget && typeof widget === 'object' && 'getTrackableWidgets' in widget;
}
}

Expand Down
5 changes: 2 additions & 3 deletions packages/core/src/browser/shell/shell-layout-restorer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -46,9 +46,8 @@ export interface StatefulWidget {
}

export namespace StatefulWidget {
// eslint-disable-next-line @typescript-eslint/no-explicit-any
export function is(arg: any): arg is StatefulWidget {
return arg !== undefined && typeof arg['storeState'] === 'function' && typeof arg['restoreState'] === 'function';
export function is(arg: unknown): arg is StatefulWidget {
return !!arg && typeof arg === 'object' && typeof (arg as StatefulWidget).storeState === 'function' && typeof (arg as StatefulWidget).restoreState === 'function';
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -171,9 +171,8 @@ export namespace TabBarToolbarItem {
return (left.priority || 0) - (right.priority || 0);
};

export function is(arg: Object | undefined): arg is TabBarToolbarItem {
// eslint-disable-next-line @typescript-eslint/no-explicit-any
return !!arg && 'command' in arg && typeof (arg as any).command === 'string';
export function is(arg: unknown): arg is TabBarToolbarItem {
return !!arg && typeof arg === 'object' && 'command' in arg && typeof (arg as TabBarToolbarItem).command === 'string';
}

}
Expand Down
1 change: 0 additions & 1 deletion packages/core/src/browser/shell/tab-bars.ts
Original file line number Diff line number Diff line change
Expand Up @@ -276,7 +276,6 @@ export class TabBarRenderer extends TabBar.Renderer {
*/
protected getDecorations(title: Title<Widget>): WidgetDecoration.Data[] {
if (this.tabBar && this.decoratorService) {
// eslint-disable-next-line @typescript-eslint/no-explicit-any
const owner: { resetTabBarDecorations?: () => void; } & Widget = title.owner;
if (!owner.resetTabBarDecorations) {
owner.resetTabBarDecorations = () => this.decorations.delete(title);
Expand Down
3 changes: 1 addition & 2 deletions packages/core/src/browser/shell/view-contribution.ts
Original file line number Diff line number Diff line change
Expand Up @@ -41,8 +41,7 @@ export interface ViewContributionOptions {
toggleKeybinding?: string;
}

// eslint-disable-next-line @typescript-eslint/no-explicit-any
export function bindViewContribution<T extends AbstractViewContribution<any>>(bind: interfaces.Bind, identifier: interfaces.Newable<T>): interfaces.BindingWhenOnSyntax<T> {
export function bindViewContribution<T extends AbstractViewContribution<Widget>>(bind: interfaces.Bind, identifier: interfaces.Newable<T>): interfaces.BindingWhenOnSyntax<T> {
const syntax = bind<T>(identifier).toSelf().inSingletonScope();
bind(CommandContribution).toService(identifier);
bind(KeybindingContribution).toService(identifier);
Expand Down
7 changes: 3 additions & 4 deletions packages/core/src/browser/source-tree/tree-source.ts
Original file line number Diff line number Diff line change
Expand Up @@ -38,11 +38,10 @@ export interface CompositeTreeElement extends TreeElement {
getElements(): MaybePromise<IterableIterator<TreeElement>>
}
export namespace CompositeTreeElement {
/* eslint-disable @typescript-eslint/no-explicit-any */
export function is(element: CompositeTreeElement | any): element is CompositeTreeElement {
return !!element && 'getElements' in element;
export function is(element: unknown): element is CompositeTreeElement {
return !!element && typeof element === 'object' && 'getElements' in element;
}
export function hasElements(element: CompositeTreeElement | any): element is CompositeTreeElement {
export function hasElements(element: unknown): element is CompositeTreeElement {
return is(element) && element.hasElements !== false;
}
}
Expand Down
4 changes: 2 additions & 2 deletions packages/core/src/browser/tree/tree-expansion.ts
Original file line number Diff line number Diff line change
Expand Up @@ -69,11 +69,11 @@ export namespace ExpandableTreeNode {
return !!node && CompositeTreeNode.is(node) && 'expanded' in node;
}

export function isExpanded(node: Object | undefined): node is ExpandableTreeNode {
export function isExpanded(node: unknown): node is ExpandableTreeNode {
return ExpandableTreeNode.is(node) && node.expanded;
}

export function isCollapsed(node: Object | undefined): node is ExpandableTreeNode {
export function isCollapsed(node: unknown): node is ExpandableTreeNode {
return ExpandableTreeNode.is(node) && !node.expanded;
}
}
Expand Down
2 changes: 1 addition & 1 deletion packages/core/src/browser/tree/tree-selection-state.ts
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ export namespace FocusableTreeSelection {
/**
* `true` if the argument is a focusable tree selection. Otherwise, `false`.
*/
export function is(arg: object | undefined): arg is FocusableTreeSelection {
export function is(arg: unknown): arg is FocusableTreeSelection {
return TreeSelection.is(arg) && 'focus' in arg;
}

Expand Down
10 changes: 5 additions & 5 deletions packages/core/src/browser/tree/tree-selection.ts
Original file line number Diff line number Diff line change
Expand Up @@ -86,8 +86,8 @@ export namespace TreeSelection {
RANGE
}

export function is(arg: Object | undefined): arg is TreeSelection {
return !!arg && 'node' in arg;
export function is(arg: unknown): arg is TreeSelection {
return !!arg && typeof arg === 'object' && 'node' in arg;
}

export function isRange(arg: TreeSelection | SelectionType | undefined): boolean {
Expand Down Expand Up @@ -129,11 +129,11 @@ export interface SelectableTreeNode extends TreeNode {

export namespace SelectableTreeNode {

export function is(node: TreeNode | undefined): node is SelectableTreeNode {
return !!node && 'selected' in node;
export function is(node: unknown): node is SelectableTreeNode {
return TreeNode.is(node) && 'selected' in node;
}

export function isSelected(node: TreeNode | undefined): node is SelectableTreeNode {
export function isSelected(node: unknown): node is SelectableTreeNode {
return is(node) && node.selected;
}

Expand Down
9 changes: 4 additions & 5 deletions packages/core/src/browser/tree/tree-widget-selection.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,15 +21,14 @@ export type TreeWidgetSelection = ReadonlyArray<Readonly<SelectableTreeNode>> &
source: TreeWidget
};
export namespace TreeWidgetSelection {
export function isSource(selection: Object | undefined, source: TreeWidget): selection is TreeWidgetSelection {
export function isSource(selection: unknown, source: TreeWidget): selection is TreeWidgetSelection {
return getSource(selection) === source;
}
export function getSource(selection: Object | undefined): TreeWidget | undefined {
export function getSource(selection: unknown): TreeWidget | undefined {
return is(selection) ? selection.source : undefined;
}
export function is(selection: Object | undefined): selection is TreeWidgetSelection {
// eslint-disable-next-line @typescript-eslint/no-explicit-any
return Array.isArray(selection) && ('source' in selection) && <any>selection['source'] instanceof TreeWidget;
export function is(selection: unknown): selection is TreeWidgetSelection {
return Array.isArray(selection) && ('source' in selection) && (selection as TreeWidgetSelection).source instanceof TreeWidget;
}

export function create(source: TreeWidget): TreeWidgetSelection {
Expand Down
2 changes: 1 addition & 1 deletion packages/core/src/browser/tree/tree.ts
Original file line number Diff line number Diff line change
Expand Up @@ -123,7 +123,7 @@ export interface TreeNode {
}

export namespace TreeNode {
export function is(node: Object | undefined): node is TreeNode {
export function is(node: unknown): node is TreeNode {
return !!node && typeof node === 'object' && 'id' in node && 'parent' in node;
}

Expand Down
4 changes: 2 additions & 2 deletions packages/core/src/browser/view-container.ts
Original file line number Diff line number Diff line change
Expand Up @@ -63,13 +63,13 @@ export interface BadgeWidget {
}

export namespace DescriptionWidget {
export function is(arg: Object | undefined): arg is DescriptionWidget {
export function is(arg: unknown): arg is DescriptionWidget {
return !!arg && typeof arg === 'object' && 'onDidChangeDescription' in arg;
}
}

export namespace BadgeWidget {
export function is(arg: Object | undefined): arg is BadgeWidget {
export function is(arg: unknown): arg is BadgeWidget {
return !!arg && typeof arg === 'object' && 'onDidChangeBadge' in arg;
}
}
Expand Down
5 changes: 2 additions & 3 deletions packages/core/src/browser/widgets/widget.ts
Original file line number Diff line number Diff line change
Expand Up @@ -246,9 +246,8 @@ export interface EventListenerObject<K extends keyof HTMLElementEventMap> {
handleEvent(evt: HTMLElementEventMap[K]): void;
}
export namespace EventListenerObject {
// eslint-disable-next-line @typescript-eslint/no-explicit-any
export function is<K extends keyof HTMLElementEventMap>(listener: any | undefined): listener is EventListenerObject<K> {
return !!listener && 'handleEvent' in listener;
export function is<K extends keyof HTMLElementEventMap>(listener: unknown): listener is EventListenerObject<K> {
return !!listener && typeof listener === 'object' && 'handleEvent' in listener;
}
}
export type EventListenerOrEventListenerObject<K extends keyof HTMLElementEventMap> = EventListener<K> | EventListenerObject<K>;
Expand Down
3 changes: 1 addition & 2 deletions packages/core/src/common/cancellation.ts
Original file line number Diff line number Diff line change
Expand Up @@ -50,8 +50,7 @@ export namespace CancellationToken {
onCancellationRequested: shortcutEvent
});

// eslint-disable-next-line @typescript-eslint/no-explicit-any
export function is(value: any): value is CancellationToken {
export function is(value: unknown): value is CancellationToken {
const candidate = value as CancellationToken;
return candidate && (candidate === CancellationToken.None
|| candidate === CancellationToken.Cancelled
Expand Down
Loading