chore: resolve linting errors & warnings

This commit is contained in:
M. George Hansen 2020-06-01 23:29:59 -07:00
parent 0572dd5738
commit 1012cdd3fa
Signed by: mgeorgehansen
SSH key fingerprint: SHA256:JlIGiQLPyQ2RHTH3a2oVlb20Xkh9Glr8DUF4YTXHJxM
11 changed files with 177 additions and 144 deletions

View file

@ -6,7 +6,7 @@
import { areEqual, displayValue, matches } from "./utils";
class ExpectError extends Error {
public constructor(reason: string, expected: any, actual: any) {
public constructor(reason: string, expected: unknown, actual: unknown) {
super(
`${reason}\n` +
`\texpected: ${displayValue(expected)}\n` +
@ -45,7 +45,7 @@ export class Expect<T> {
*
* @throws ExpectError If the actual value does not equal the expected value.
*/
public toEqual(expected: T) {
public toEqual(expected: T): void {
if (!areEqual(this.value, expected)) {
throw new ExpectError(
`value does not equal expected`,
@ -201,12 +201,12 @@ export function expect<T>(fn: () => T): FunctionExpect<T>;
*
* @param value Value to place expectations upon.
*/
export function expect(value: any): Expect<any> {
export function expect(value: unknown): Expect<unknown> {
if (typeof value === "string") {
return new StringExpect(value);
}
if (typeof value === "function") {
return new FunctionExpect(value);
return new FunctionExpect(value as () => unknown);
}
return new Expect(value);
}

View file

@ -31,7 +31,10 @@ const areArraysEqual = <T>(a: T[], b: T[]): boolean => {
return true;
};
const areObjectsEqual = <T extends object>(a: T, b: T): boolean => {
const areObjectsEqual = <T extends Record<string, unknown>>(
a: T,
b: T
): boolean => {
const aKeys = Object.keys(a) as Array<keyof T>;
const bKeys = Object.keys(b) as Array<keyof T>;
if (aKeys.length !== bKeys.length) {
@ -62,7 +65,10 @@ export const areEqual = <T>(a: T, b: T): boolean => {
return a.source === b.source;
}
if (typeof a === "object" && typeof b === "object") {
return areObjectsEqual(a as any, b);
return areObjectsEqual(
a as Record<string, unknown>,
b as Record<string, unknown>
);
}
return a === b;
};
@ -95,7 +101,7 @@ export const matches = (value: string, pattern: string | RegExp): boolean => {
*
* @return Rendered value to display.
*/
export const displayValue = (value: any): string => {
export const displayValue = (value: unknown): string => {
if (value === undefined) {
return "undefined";
}