Fixup type errors

Signed-off-by: Sebastian Malton <sebastian@malton.name>
This commit is contained in:
Sebastian Malton committed 2023-03-02 13:30:57 -05:00
1 parent 2301270d54
commit 45b630553a
31 files changed
+60 -60

No files matched your search

@@ -3,9 +3,9 @@
* Licensed under MIT License. See LICENSE in root directory for more information.
*/
import type { AsyncResult } from "./async-result";
import type { AsyncResult, Result } from "./result";
import { delay } from "./delay";
import { noop } from "@k8slens/utilities/src/noop";
import { noop } from "./noop";
/**
* @param error The error that resulted in the failure
@@ -25,7 +25,7 @@ export interface BackoffCallerOptions<E> {
maxAttempts?: number;
/**
* In miliseconds
* In milliseconds
* @default 1000
*/
initialTimeout?: number;
@@ -41,7 +41,7 @@ export interface BackoffCallerOptions<E> {
* @param fn The function to repeatedly attempt
* @returns The first success or the last failure
*/
export const backoffCaller = async <T, E, R extends AsyncResult<T, E>>(fn: () => Promise<R>, options?: BackoffCallerOptions<E>): Promise<R> => {
export const backoffCaller = async <T, E>(fn: () => AsyncResult<T, E>, options?: BackoffCallerOptions<E>): AsyncResult<T, E> => {
const {
initialTimeout = 1000,
maxAttempts = 5,
@@ -51,7 +51,7 @@ export const backoffCaller = async <T, E, R extends AsyncResult<T, E>>(fn: () =>
let timeout = initialTimeout;
let attempt = 0;
let result: R;
let result: Result<T, E>;
do {
result = await fn();
@@ -7,7 +7,7 @@
import { camelCase } from "lodash";
import type { SingleOrMany } from "./types";
import { isObject, isString } from "./type-narrowing";
import * as object from "./object";
import { object } from "./object";
export function toCamelCase<T extends Record<string, unknown>[]>(obj: T): T;
export function toCamelCase<T extends Record<string, unknown>>(obj: T): T;
@@ -3,8 +3,8 @@
* Licensed under MIT License. See LICENSE in root directory for more information.
*/
import * as iter from "./iter";
import * as object from "./object";
import { iter } from "./iter";
import { object } from "./object";
import { isObject } from "./type-narrowing";
export type IgnoredClassNames = number | symbol | Function;
@@ -4,7 +4,7 @@
*/
import type { IInterceptable, IInterceptor, IListenable, ISetWillChange, ObservableMap } from "mobx";
import { action, observable, ObservableSet } from "mobx";
import { observable, ObservableSet, runInAction } from "mobx";
export function makeIterableIterator<T>(iterator: Iterator<T>): IterableIterator<T> {
(iterator as IterableIterator<T>)[Symbol.iterator] = () => iterator as IterableIterator<T>;
@@ -138,23 +138,24 @@ export class ObservableHashSet<T> implements Set<T>, IInterceptable<ISetWillChan
this.#hashmap = observable.map<string, T>(Array.from(initialValues, value => [this.hasher(value), value]), undefined);
}
@action
replace(other: ObservableHashSet<T> | ObservableSet<T> | Set<T> | readonly T[]): this {
if (other === null || other === undefined) {
return runInAction(() => {
if (other === null || other === undefined) {
return this;
}
if (!(Array.isArray(other) || other instanceof Set || other instanceof ObservableHashSet || other instanceof ObservableSet)) {
throw new Error(`ObservableHashSet: Cannot initialize set from ${other}`);
}
this.clear();
for (const value of other) {
this.add(value);
}
return this;
}
if (!(Array.isArray(other) || other instanceof Set || other instanceof ObservableHashSet || other instanceof ObservableSet)) {
throw new Error(`ObservableHashSet: Cannot initialize set from ${other}`);
}
this.clear();
for (const value of other) {
this.add(value);
}
return this;
});
}
clear(): void {
@@ -167,15 +168,16 @@ export class ObservableHashSet<T> implements Set<T>, IInterceptable<ISetWillChan
return this;
}
@action
toggle(value: T): void {
const hash = this.hasher(value);
runInAction(() => {
const hash = this.hasher(value);
if (this.#hashmap.has(hash)) {
this.#hashmap.delete(hash);
} else {
this.#hashmap.set(hash, value);
}
if (this.#hashmap.has(hash)) {
this.#hashmap.delete(hash);
} else {
this.#hashmap.set(hash, value);
}
});
}
delete(value: T): boolean {
@@ -3,8 +3,6 @@
* Licensed under MIT License. See LICENSE in root directory for more information.
*/
import type { WindowEventListener } from "../window/event-listener.injectable";
function parseKeyDownDescriptor(descriptor: string): (event: KeyboardEvent) => boolean {
const parts = new Set((
descriptor
@@ -43,7 +41,7 @@ function parseKeyDownDescriptor(descriptor: string): (event: KeyboardEvent) => b
};
}
export function onKeyboardShortcut(descriptor: string, action: () => void): WindowEventListener<"keydown"> {
export function onKeyboardShortcut(descriptor: string, action: () => void): (this: Window, ev: WindowEventMap["keydown"]) => any {
const isMatchingEvent = parseKeyDownDescriptor(descriptor);
return (event) => {
@@ -4,7 +4,7 @@
*/
import path from "path";
import * as iter from "@k8slens/utilities/src/iter";
import { iter } from "./iter";
/**
* Join all entires with a PATH env var delimited string together