2989: vscode extension: migrate from any to unknown where possible r=Veetaha a=Veetaha

`unknown` type is the stricter version of `any` and it should always be prefered (like `const` over `let`).
It lets you assign any value to it, but doesn't let you carry out arbitrary operations on them without an explicit type check (like `typeof unknownValue === 'string'`).

Co-authored-by: Veetaha <gerzoh1@gmail.com>
This commit is contained in:
bors[bot] 2020-02-02 21:27:58 +00:00 committed by GitHub
commit ae16884b95
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
5 changed files with 15 additions and 11 deletions

View file

@ -68,7 +68,7 @@ PATH=${process.env.PATH}
// This also requires considering our settings strategy, which is work which needs doing
// @ts-ignore The tracer is private to vscode-languageclient, but we need access to it to not log publishDecorations requests
res._tracer = {
log: (messageOrDataObject: string | any, data?: string) => {
log: (messageOrDataObject: string | unknown, data?: string) => {
if (typeof messageOrDataObject === 'string') {
if (
messageOrDataObject.includes(

View file

@ -61,7 +61,7 @@ export class ColorTheme {
}
function loadThemeNamed(themeName: string): ColorTheme {
function isTheme(extension: vscode.Extension<any>): boolean {
function isTheme(extension: vscode.Extension<unknown>): boolean {
return (
extension.extensionKind === vscode.ExtensionKind.UI &&
extension.packageJSON.contributes &&

View file

@ -55,7 +55,7 @@ export function syntaxTree(ctx: Ctx): Cmd {
// We need to order this after LS updates, but there's no API for that.
// Hence, good old setTimeout.
function afterLs(f: () => any) {
function afterLs(f: () => void) {
setTimeout(f, 10);
}

View file

@ -1,5 +1,6 @@
import * as vscode from 'vscode';
import * as lc from 'vscode-languageclient';
import { Config } from './config';
import { createClient } from './client';
@ -52,12 +53,12 @@ export class Ctx {
overrideCommand(name: string, factory: (ctx: Ctx) => Cmd) {
const defaultCmd = `default:${name}`;
const override = factory(this);
const original = (...args: any[]) =>
const original = (...args: unknown[]) =>
vscode.commands.executeCommand(defaultCmd, ...args);
try {
const d = vscode.commands.registerCommand(
name,
async (...args: any[]) => {
async (...args: unknown[]) => {
if (!(await override(...args))) {
return await original(...args);
}
@ -73,11 +74,11 @@ export class Ctx {
}
}
get subscriptions(): { dispose(): any }[] {
get subscriptions(): Disposable[] {
return this.extCtx.subscriptions;
}
pushCleanup(d: { dispose(): any }) {
pushCleanup(d: Disposable) {
this.extCtx.subscriptions.push(d);
}
@ -86,12 +87,15 @@ export class Ctx {
}
}
export type Cmd = (...args: any[]) => any;
export interface Disposable {
dispose(): void;
}
export type Cmd = (...args: any[]) => unknown;
export async function sendRequestWithRetry<R>(
client: lc.LanguageClient,
method: string,
param: any,
param: unknown,
token?: vscode.CancellationToken,
): Promise<R> {
for (const delay of [2, 4, 6, 8, 10, null]) {

View file

@ -1,6 +1,6 @@
import * as vscode from 'vscode';
import { WorkDoneProgress, WorkDoneProgressBegin, WorkDoneProgressReport, WorkDoneProgressEnd } from 'vscode-languageclient';
import { WorkDoneProgress, WorkDoneProgressBegin, WorkDoneProgressReport, WorkDoneProgressEnd, Disposable } from 'vscode-languageclient';
import { Ctx } from './ctx';
@ -14,7 +14,7 @@ export function activateStatusDisplay(ctx: Ctx) {
});
}
class StatusDisplay implements vscode.Disposable {
class StatusDisplay implements vscode.Disposable, Disposable {
packageName?: string;
private i: number = 0;