Skip to content

Commit a949694

Browse files
author
Benjamin Pasero
committed
debt - reduce usage of explicit any
1 parent e5834d3 commit a949694

49 files changed

Lines changed: 258 additions & 299 deletions

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

.eslintrc.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,8 @@
3535
"external",
3636
"status",
3737
"origin",
38-
"orientation"
38+
"orientation",
39+
"context"
3940
], // non-complete list of globals that are easy to access unintentionally
4041
"no-var": "warn",
4142
"jsdoc/no-types": "warn",

src/vs/base/browser/fastDomNode.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -244,11 +244,11 @@ export class FastDomNode<T extends HTMLElement> {
244244
this.domNode.removeAttribute(name);
245245
}
246246

247-
public appendChild(child: FastDomNode<any>): void {
247+
public appendChild(child: FastDomNode<T>): void {
248248
this.domNode.appendChild(child.domNode);
249249
}
250250

251-
public removeChild(child: FastDomNode<any>): void {
251+
public removeChild(child: FastDomNode<T>): void {
252252
this.domNode.removeChild(child.domNode);
253253
}
254254
}

src/vs/base/browser/iframe.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -98,7 +98,7 @@ export class IframeUtils {
9898
/**
9999
* Returns the position of `childWindow` relative to `ancestorWindow`
100100
*/
101-
public static getPositionOfChildWindowRelativeToAncestorWindow(childWindow: Window, ancestorWindow: any) {
101+
public static getPositionOfChildWindowRelativeToAncestorWindow(childWindow: Window, ancestorWindow: Window) {
102102

103103
if (!ancestorWindow || childWindow === ancestorWindow) {
104104
return {

src/vs/base/browser/touch.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -131,7 +131,7 @@ export class Gesture extends Disposable {
131131

132132
@memoize
133133
private static isTouchDevice(): boolean {
134-
return 'ontouchstart' in window as any || navigator.maxTouchPoints > 0 || window.navigator.msMaxTouchPoints > 0;
134+
return 'ontouchstart' in window || navigator.maxTouchPoints > 0 || window.navigator.msMaxTouchPoints > 0;
135135
}
136136

137137
public dispose(): void {

src/vs/base/browser/ui/actionbar/actionbar.ts

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -104,7 +104,7 @@ export class BaseActionViewItem extends Disposable implements IActionViewItem {
104104
return this._action.enabled;
105105
}
106106

107-
setActionContext(newContext: any): void {
107+
setActionContext(newContext: unknown): void {
108108
this._context = newContext;
109109
}
110110

@@ -248,7 +248,7 @@ export class ActionViewItem extends BaseActionViewItem {
248248

249249
private cssClass?: string;
250250

251-
constructor(context: any, action: IAction, options: IActionViewItemOptions = {}) {
251+
constructor(context: unknown, action: IAction, options: IActionViewItemOptions = {}) {
252252
super(context, action, options);
253253

254254
this.options = options;
@@ -423,7 +423,7 @@ export class ActionBar extends Disposable implements IActionRunner {
423423
options: IActionBarOptions;
424424

425425
private _actionRunner: IActionRunner;
426-
private _context: any;
426+
private _context: unknown;
427427

428428
// View Items
429429
viewItems: IActionViewItem[];
@@ -821,7 +821,7 @@ export class ActionBar extends Disposable implements IActionRunner {
821821
this._onDidCancel.fire();
822822
}
823823

824-
run(action: IAction, context?: any): Promise<void> {
824+
run(action: IAction, context?: unknown): Promise<void> {
825825
return this._actionRunner.run(action, context);
826826
}
827827

@@ -838,7 +838,7 @@ export class ActionBar extends Disposable implements IActionRunner {
838838
export class SelectActionViewItem extends BaseActionViewItem {
839839
protected selectBox: SelectBox;
840840

841-
constructor(ctx: any, action: IAction, options: ISelectOptionItem[], selected: number, contextViewProvider: IContextViewProvider, selectBoxOptions?: ISelectBoxOptions) {
841+
constructor(ctx: unknown, action: IAction, options: ISelectOptionItem[], selected: number, contextViewProvider: IContextViewProvider, selectBoxOptions?: ISelectBoxOptions) {
842842
super(ctx, action);
843843

844844
this.selectBox = new SelectBox(options, selected, contextViewProvider, undefined, selectBoxOptions);

src/vs/base/browser/ui/toolbar/toolbar.ts

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -86,7 +86,7 @@ export class ToolBar extends Disposable {
8686
return this.actionBar.actionRunner;
8787
}
8888

89-
set context(context: any) {
89+
set context(context: unknown) {
9090
this.actionBar.context = context;
9191
if (this.toggleMenuActionViewItem.value) {
9292
this.toggleMenuActionViewItem.value.setActionContext(context);
@@ -166,10 +166,8 @@ class ToggleMenuAction extends Action {
166166
this.toggleDropdownMenu = toggleDropdownMenu;
167167
}
168168

169-
run(): Promise<any> {
169+
async run(): Promise<void> {
170170
this.toggleDropdownMenu();
171-
172-
return Promise.resolve(true);
173171
}
174172

175173
get menuActions(): ReadonlyArray<IAction> {

src/vs/base/common/assert.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,8 @@
66
/**
77
* Throws an error with the provided message if the provided value does not evaluate to a true Javascript value.
88
*/
9-
export function ok(value?: any, message?: string) {
9+
export function ok(value?: unknown, message?: string) {
1010
if (!value) {
11-
throw new Error(message ? 'Assertion failed (' + message + ')' : 'Assertion Failed');
11+
throw new Error(message ? `Assertion failed (${message})` : 'Assertion Failed');
1212
}
1313
}

src/vs/base/common/stream.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -95,8 +95,8 @@ export interface WriteableStream<T> extends ReadableStream<T> {
9595
end(result?: T | Error): void;
9696
}
9797

98-
export function isReadableStream<T>(obj: any): obj is ReadableStream<T> {
99-
const candidate: ReadableStream<T> = obj;
98+
export function isReadableStream<T>(obj: unknown): obj is ReadableStream<T> {
99+
const candidate = obj as ReadableStream<T>;
100100

101101
return candidate && [candidate.on, candidate.pause, candidate.resume, candidate.destroy].every(fn => typeof fn === 'function');
102102
}

src/vs/base/common/strings.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -240,7 +240,7 @@ export function regExpFlags(regexp: RegExp): string {
240240
return (regexp.global ? 'g' : '')
241241
+ (regexp.ignoreCase ? 'i' : '')
242242
+ (regexp.multiline ? 'm' : '')
243-
+ ((regexp as any).unicode ? 'u' : '');
243+
+ (regexp.unicode ? 'u' : '');
244244
}
245245

246246
/**
@@ -853,15 +853,15 @@ export function removeAnsiEscapeCodes(str: string): string {
853853
}
854854

855855
export const removeAccents: (str: string) => string = (function () {
856-
if (typeof (String.prototype as any).normalize !== 'function') {
856+
if (typeof String.prototype.normalize !== 'function') {
857857
// ☹️ no ES6 features...
858858
return function (str: string) { return str; };
859859
} else {
860860
// transform into NFD form and remove accents
861861
// see: https://stackoverflow.com/questions/990904/remove-accents-diacritics-in-a-string-in-javascript/37511463#37511463
862862
const regex = /[\u0300-\u036f]/g;
863863
return function (str: string) {
864-
return (str as any).normalize('NFD').replace(regex, '');
864+
return str.normalize('NFD').replace(regex, '');
865865
};
866866
}
867867
})();

src/vs/base/node/crypto.ts

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -5,19 +5,17 @@
55

66
import * as fs from 'fs';
77
import * as crypto from 'crypto';
8-
import * as stream from 'stream';
98
import { once } from 'vs/base/common/functional';
109

1110
export function checksum(path: string, sha1hash: string | undefined): Promise<void> {
1211
const promise = new Promise<string | undefined>((c, e) => {
1312
const input = fs.createReadStream(path);
1413
const hash = crypto.createHash('sha1');
15-
const hashStream = hash as any as stream.PassThrough;
16-
input.pipe(hashStream);
14+
input.pipe(hash);
1715

1816
const done = once((err?: Error, result?: string) => {
1917
input.removeAllListeners();
20-
hashStream.removeAllListeners();
18+
hash.removeAllListeners();
2119

2220
if (err) {
2321
e(err);
@@ -28,8 +26,8 @@ export function checksum(path: string, sha1hash: string | undefined): Promise<vo
2826

2927
input.once('error', done);
3028
input.once('end', done);
31-
hashStream.once('error', done);
32-
hashStream.once('data', (data: Buffer) => done(undefined, data.toString('hex')));
29+
hash.once('error', done);
30+
hash.once('data', (data: Buffer) => done(undefined, data.toString('hex')));
3331
});
3432

3533
return promise.then(hash => {

0 commit comments

Comments
 (0)