mirror of
https://github.com/microsoft/vscode.git
synced 2026-05-24 01:11:34 +01:00
Fix a few simple anys in extensions
This commit is contained in:
@@ -8,7 +8,7 @@ import { Disposable } from './util/dispose';
|
||||
|
||||
|
||||
export interface ILogger {
|
||||
trace(title: string, message: string, data?: any): void;
|
||||
trace(title: string, message: string, data?: unknown): void;
|
||||
}
|
||||
|
||||
export class VsCodeOutputLogger extends Disposable implements ILogger {
|
||||
@@ -23,7 +23,7 @@ export class VsCodeOutputLogger extends Disposable implements ILogger {
|
||||
super();
|
||||
}
|
||||
|
||||
public trace(title: string, message: string, data?: any): void {
|
||||
public trace(title: string, message: string, data?: unknown): void {
|
||||
this.#outputChannel.trace(`${title}: ${message}`, ...(data ? [JSON.stringify(data, null, 4)] : []));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -10,7 +10,7 @@ export interface ITask<T> {
|
||||
export class Delayer<T> {
|
||||
|
||||
public defaultDelay: number;
|
||||
#timeout: any; // Timer
|
||||
#timeout: ReturnType<typeof setTimeout> | null;
|
||||
#cancelTimeout: Promise<T | null> | null;
|
||||
#onSuccess: ((value: T | PromiseLike<T> | undefined) => void) | null;
|
||||
#task: ITask<T> | null;
|
||||
|
||||
@@ -5,8 +5,8 @@
|
||||
|
||||
import * as vscode from 'vscode';
|
||||
|
||||
export function disposeAll(disposables: Iterable<vscode.Disposable>) {
|
||||
const errors: any[] = [];
|
||||
export function disposeAll(disposables: Iterable<vscode.Disposable>): void {
|
||||
const errors: unknown[] = [];
|
||||
|
||||
for (const disposable of disposables) {
|
||||
try {
|
||||
@@ -32,7 +32,7 @@ export abstract class Disposable {
|
||||
|
||||
protected _disposables: vscode.Disposable[] = [];
|
||||
|
||||
public dispose(): any {
|
||||
public dispose(): void {
|
||||
if (this.#isDisposed) {
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -5,7 +5,7 @@
|
||||
|
||||
import * as vscode from 'vscode';
|
||||
|
||||
export function disposeAll(disposables: vscode.Disposable[]) {
|
||||
export function disposeAll(disposables: vscode.Disposable[]): void {
|
||||
while (disposables.length) {
|
||||
const item = disposables.pop();
|
||||
if (item) {
|
||||
@@ -19,7 +19,7 @@ export abstract class Disposable {
|
||||
|
||||
protected _disposables: vscode.Disposable[] = [];
|
||||
|
||||
public dispose(): any {
|
||||
public dispose(): void {
|
||||
if (this._isDisposed) {
|
||||
return;
|
||||
}
|
||||
@@ -39,4 +39,4 @@ export abstract class Disposable {
|
||||
protected get isDisposed() {
|
||||
return this._isDisposed;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -5,7 +5,7 @@
|
||||
|
||||
import * as vscode from 'vscode';
|
||||
|
||||
export function disposeAll(disposables: vscode.Disposable[]) {
|
||||
export function disposeAll(disposables: vscode.Disposable[]): void {
|
||||
while (disposables.length) {
|
||||
const item = disposables.pop();
|
||||
item?.dispose();
|
||||
@@ -17,7 +17,7 @@ export abstract class Disposable {
|
||||
|
||||
protected _disposables: vscode.Disposable[] = [];
|
||||
|
||||
public dispose(): any {
|
||||
public dispose(): void {
|
||||
if (this._isDisposed) {
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -5,14 +5,61 @@
|
||||
|
||||
import { onceDocumentLoaded } from './events';
|
||||
|
||||
interface SimpleBrowserSettings {
|
||||
readonly url: string;
|
||||
readonly focusLockEnabled: boolean;
|
||||
}
|
||||
|
||||
interface SimpleBrowserState {
|
||||
readonly url: string;
|
||||
}
|
||||
|
||||
interface OpenExternalMessage {
|
||||
readonly type: 'openExternal';
|
||||
readonly url: string;
|
||||
}
|
||||
|
||||
type ExtensionToWebviewMessage =
|
||||
| { readonly type: 'focus' }
|
||||
| { readonly type: 'didChangeFocusLockIndicatorEnabled'; readonly focusLockEnabled: boolean };
|
||||
|
||||
interface VsCodeApi<State, Message> {
|
||||
setState(state: State): void;
|
||||
postMessage(message: Message): void;
|
||||
}
|
||||
|
||||
declare function acquireVsCodeApi(): VsCodeApi<SimpleBrowserState, OpenExternalMessage>;
|
||||
|
||||
const vscode = acquireVsCodeApi();
|
||||
|
||||
function getSettings() {
|
||||
function isSimpleBrowserSettings(value: unknown): value is SimpleBrowserSettings {
|
||||
return typeof value === 'object'
|
||||
&& value !== null
|
||||
&& 'url' in value
|
||||
&& typeof value.url === 'string'
|
||||
&& 'focusLockEnabled' in value
|
||||
&& typeof value.focusLockEnabled === 'boolean';
|
||||
}
|
||||
|
||||
function isExtensionToWebviewMessage(value: unknown): value is ExtensionToWebviewMessage {
|
||||
return typeof value === 'object'
|
||||
&& value !== null
|
||||
&& 'type' in value
|
||||
&& (value.type === 'focus'
|
||||
|| (value.type === 'didChangeFocusLockIndicatorEnabled'
|
||||
&& 'focusLockEnabled' in value
|
||||
&& typeof value.focusLockEnabled === 'boolean'));
|
||||
}
|
||||
|
||||
function getSettings(): SimpleBrowserSettings {
|
||||
const element = document.getElementById('simple-browser-settings');
|
||||
if (element) {
|
||||
const data = element.getAttribute('data-settings');
|
||||
if (data) {
|
||||
return JSON.parse(data);
|
||||
const settings: unknown = JSON.parse(data);
|
||||
if (isSimpleBrowserSettings(settings)) {
|
||||
return settings;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -30,7 +77,12 @@ const reloadButton = header.querySelector<HTMLButtonElement>('.reload-button')!;
|
||||
const openExternalButton = header.querySelector<HTMLButtonElement>('.open-external-button')!;
|
||||
|
||||
window.addEventListener('message', e => {
|
||||
switch (e.data.type) {
|
||||
const message: unknown = e.data;
|
||||
if (!isExtensionToWebviewMessage(message)) {
|
||||
return;
|
||||
}
|
||||
|
||||
switch (message.type) {
|
||||
case 'focus':
|
||||
{
|
||||
iframe.focus();
|
||||
@@ -38,7 +90,7 @@ window.addEventListener('message', e => {
|
||||
}
|
||||
case 'didChangeFocusLockIndicatorEnabled':
|
||||
{
|
||||
toggleFocusLockIndicatorEnabled(e.data.enabled);
|
||||
toggleFocusLockIndicatorEnabled(message.focusLockEnabled);
|
||||
break;
|
||||
}
|
||||
}
|
||||
@@ -87,7 +139,7 @@ onceDocumentLoaded(() => {
|
||||
navigateTo(settings.url);
|
||||
input.value = settings.url;
|
||||
|
||||
toggleFocusLockIndicatorEnabled(settings.focusLockIndicatorEnabled);
|
||||
toggleFocusLockIndicatorEnabled(settings.focusLockEnabled);
|
||||
|
||||
function navigateTo(rawUrl: string): void {
|
||||
try {
|
||||
|
||||
@@ -5,7 +5,7 @@
|
||||
|
||||
import * as vscode from 'vscode';
|
||||
|
||||
export function disposeAll(disposables: vscode.Disposable[]) {
|
||||
export function disposeAll(disposables: vscode.Disposable[]): void {
|
||||
while (disposables.length) {
|
||||
const item = disposables.pop();
|
||||
item?.dispose();
|
||||
@@ -17,7 +17,7 @@ export abstract class Disposable {
|
||||
|
||||
protected _disposables: vscode.Disposable[] = [];
|
||||
|
||||
public dispose(): any {
|
||||
public dispose(): void {
|
||||
if (this._isDisposed) {
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -6,8 +6,8 @@
|
||||
import * as vscode from 'vscode';
|
||||
|
||||
|
||||
export function disposeAll(disposables: Iterable<vscode.Disposable>) {
|
||||
const errors: any[] = [];
|
||||
export function disposeAll(disposables: Iterable<vscode.Disposable>): void {
|
||||
const errors: unknown[] = [];
|
||||
|
||||
for (const disposable of disposables) {
|
||||
try {
|
||||
@@ -33,7 +33,7 @@ export abstract class Disposable {
|
||||
|
||||
protected _disposables: vscode.Disposable[] = [];
|
||||
|
||||
public dispose(): any {
|
||||
public dispose(): void {
|
||||
if (this._isDisposed) {
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -6,7 +6,7 @@
|
||||
/**
|
||||
* Return a hash value for an object.
|
||||
*/
|
||||
export function hash(obj: any, hashVal = 0): number {
|
||||
export function hash(obj: unknown, hashVal = 0): number {
|
||||
switch (typeof obj) {
|
||||
case 'object':
|
||||
if (obj === null) {
|
||||
@@ -24,7 +24,7 @@ export function hash(obj: any, hashVal = 0): number {
|
||||
case 'undefined':
|
||||
return 937 * 31;
|
||||
default:
|
||||
return numberHash(obj, 617);
|
||||
return stringHash(String(obj), 617);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -44,15 +44,15 @@ function stringHash(s: string, hashVal: number) {
|
||||
return hashVal;
|
||||
}
|
||||
|
||||
function arrayHash(arr: any[], initialHashVal: number): number {
|
||||
function arrayHash(arr: readonly unknown[], initialHashVal: number): number {
|
||||
initialHashVal = numberHash(104579, initialHashVal);
|
||||
return arr.reduce((hashVal, item) => hash(item, hashVal), initialHashVal);
|
||||
return arr.reduce<number>((hashVal, item) => hash(item, hashVal), initialHashVal);
|
||||
}
|
||||
|
||||
function objectHash(obj: any, initialHashVal: number): number {
|
||||
function objectHash(obj: object, initialHashVal: number): number {
|
||||
initialHashVal = numberHash(181387, initialHashVal);
|
||||
return Object.keys(obj).sort().reduce((hashVal, key) => {
|
||||
hashVal = stringHash(key, hashVal);
|
||||
return hash(obj[key], hashVal);
|
||||
return hash(Reflect.get(obj, key), hashVal);
|
||||
}, initialHashVal);
|
||||
}
|
||||
|
||||
@@ -14,5 +14,5 @@ export function isWebAndHasSharedArrayBuffers(): boolean {
|
||||
}
|
||||
|
||||
export function supportsReadableByteStreams(): boolean {
|
||||
return isWeb() && 'ReadableByteStreamController' in globalThis;
|
||||
return isWeb() && typeof ReadableByteStreamController !== 'undefined';
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user