Skip to content

Commit ae16884

Browse files
bors[bot]Veetaha
and
Veetaha
authored
Merge #2989
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 <[email protected]>
2 parents 5e61c9b + 2fd7af2 commit ae16884

File tree

5 files changed

+15
-11
lines changed

5 files changed

+15
-11
lines changed

editors/code/src/client.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,7 @@ PATH=${process.env.PATH}
6868
// This also requires considering our settings strategy, which is work which needs doing
6969
// @ts-ignore The tracer is private to vscode-languageclient, but we need access to it to not log publishDecorations requests
7070
res._tracer = {
71-
log: (messageOrDataObject: string | any, data?: string) => {
71+
log: (messageOrDataObject: string | unknown, data?: string) => {
7272
if (typeof messageOrDataObject === 'string') {
7373
if (
7474
messageOrDataObject.includes(

editors/code/src/color_theme.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,7 @@ export class ColorTheme {
6161
}
6262

6363
function loadThemeNamed(themeName: string): ColorTheme {
64-
function isTheme(extension: vscode.Extension<any>): boolean {
64+
function isTheme(extension: vscode.Extension<unknown>): boolean {
6565
return (
6666
extension.extensionKind === vscode.ExtensionKind.UI &&
6767
extension.packageJSON.contributes &&

editors/code/src/commands/syntax_tree.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@ export function syntaxTree(ctx: Ctx): Cmd {
5555

5656
// We need to order this after LS updates, but there's no API for that.
5757
// Hence, good old setTimeout.
58-
function afterLs(f: () => any) {
58+
function afterLs(f: () => void) {
5959
setTimeout(f, 10);
6060
}
6161

editors/code/src/ctx.ts

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import * as vscode from 'vscode';
22
import * as lc from 'vscode-languageclient';
3+
34
import { Config } from './config';
45
import { createClient } from './client';
56

@@ -52,12 +53,12 @@ export class Ctx {
5253
overrideCommand(name: string, factory: (ctx: Ctx) => Cmd) {
5354
const defaultCmd = `default:${name}`;
5455
const override = factory(this);
55-
const original = (...args: any[]) =>
56+
const original = (...args: unknown[]) =>
5657
vscode.commands.executeCommand(defaultCmd, ...args);
5758
try {
5859
const d = vscode.commands.registerCommand(
5960
name,
60-
async (...args: any[]) => {
61+
async (...args: unknown[]) => {
6162
if (!(await override(...args))) {
6263
return await original(...args);
6364
}
@@ -73,11 +74,11 @@ export class Ctx {
7374
}
7475
}
7576

76-
get subscriptions(): { dispose(): any }[] {
77+
get subscriptions(): Disposable[] {
7778
return this.extCtx.subscriptions;
7879
}
7980

80-
pushCleanup(d: { dispose(): any }) {
81+
pushCleanup(d: Disposable) {
8182
this.extCtx.subscriptions.push(d);
8283
}
8384

@@ -86,12 +87,15 @@ export class Ctx {
8687
}
8788
}
8889

89-
export type Cmd = (...args: any[]) => any;
90+
export interface Disposable {
91+
dispose(): void;
92+
}
93+
export type Cmd = (...args: any[]) => unknown;
9094

9195
export async function sendRequestWithRetry<R>(
9296
client: lc.LanguageClient,
9397
method: string,
94-
param: any,
98+
param: unknown,
9599
token?: vscode.CancellationToken,
96100
): Promise<R> {
97101
for (const delay of [2, 4, 6, 8, 10, null]) {

editors/code/src/status_display.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import * as vscode from 'vscode';
22

3-
import { WorkDoneProgress, WorkDoneProgressBegin, WorkDoneProgressReport, WorkDoneProgressEnd } from 'vscode-languageclient';
3+
import { WorkDoneProgress, WorkDoneProgressBegin, WorkDoneProgressReport, WorkDoneProgressEnd, Disposable } from 'vscode-languageclient';
44

55
import { Ctx } from './ctx';
66

@@ -14,7 +14,7 @@ export function activateStatusDisplay(ctx: Ctx) {
1414
});
1515
}
1616

17-
class StatusDisplay implements vscode.Disposable {
17+
class StatusDisplay implements vscode.Disposable, Disposable {
1818
packageName?: string;
1919

2020
private i: number = 0;

0 commit comments

Comments
 (0)