ESLint: Fix more warnings and errors.

This commit is contained in:
baldo 2022-08-23 21:38:37 +02:00
parent 66fb4e5004
commit bfd6ca1d26
9 changed files with 84 additions and 56 deletions
server/shared
types
validation

View file

@ -77,6 +77,10 @@ export function isObject(arg: unknown): arg is object {
return arg !== null && typeof arg === "object";
}
export function isPlainObject(arg: unknown): arg is { [key: string]: unknown } {
return isObject(arg) && !Array.isArray(arg);
}
export function hasOwnProperty<Key extends PropertyKey>(
arg: unknown,
key: Key
@ -84,6 +88,13 @@ export function hasOwnProperty<Key extends PropertyKey>(
return isObject(arg) && key in arg;
}
export function getFieldIfExists(
arg: unknown,
key: PropertyKey
): unknown | undefined {
return hasOwnProperty(arg, key) ? arg[key] : undefined;
}
export function isArray<T>(arg: unknown, isT: TypeGuard<T>): arg is Array<T> {
if (!Array.isArray(arg)) {
return false;

View file

@ -25,6 +25,9 @@ export interface Constraint {
}
export type Constraints = { [key: string]: Constraint };
export type NestedConstraints = {
[key: string]: Constraint | Constraints | NestedConstraints;
};
export type Values = { [key: string]: unknown };
export function isConstraint(arg: unknown): arg is Constraint {