Skip to content

Commit

Permalink
Remove redundant type checks
Browse files Browse the repository at this point in the history
TypeScript already checks the types, so no need to explicitly re-check
them with `assert.ok` or `assertString`.
  • Loading branch information
nandito committed Nov 6, 2023
1 parent 197b4de commit 7f4b4eb
Show file tree
Hide file tree
Showing 7 changed files with 3 additions and 30 deletions.
3 changes: 0 additions & 3 deletions src/lib/api/ApiClient.ts
Original file line number Diff line number Diff line change
Expand Up @@ -74,9 +74,6 @@ export default class ApiClient {
baseUrl = "https://api.appearin.net",
fetchDeviceCredentials = noCredentials,
}: ApiClientOptions = {}) {
assertString(baseUrl, "baseUrl");
assert.ok(typeof fetchDeviceCredentials === "function", "fetchDeviceCredentials<Function> is required");

this.authenticatedHttpClient = new AuthenticatedHttpClient({
httpClient: new HttpClient({
baseUrl,
Expand Down
1 change: 0 additions & 1 deletion src/lib/api/HttpClient.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@ export interface IHttpClient {
}

function _getAbsoluteUrl({ baseUrl, url }: { baseUrl?: string; url: string }): string {
assert.ok(typeof url === "string", "url<String> is required");
return baseUrl ? baseUrl + url : url;
}

Expand Down
7 changes: 3 additions & 4 deletions src/lib/api/OrganizationApiClient.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,9 @@ export default class OrganizationApiClient {
/**
* Create an OrganizationApiClient instance.
*
* @param {ApiClient} [apiClient] - The apiClient to use.
* @param {Function} [fetchOrganization] - function that returns a promise with the organization.
* @param {Object} options - The options for the OrganizationApiClient.
* @param {ApiClient} [options.apiClient] - The apiClient to use.
* @param {Function} [options.fetchOrganization] - function that returns a promise with the organization.
*/
constructor({
apiClient,
Expand All @@ -29,8 +30,6 @@ export default class OrganizationApiClient {
fetchOrganization?: FetchOrganizationFunction;
}) {
this._apiClient = apiClient;
assert.ok(typeof fetchOrganization === "function", "fetchOrganization<Function> is required");

this._fetchOrganization = fetchOrganization;
this._apiClient = apiClient;
}
Expand Down
8 changes: 0 additions & 8 deletions src/lib/api/test/ApiClient.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,11 +16,6 @@ describe("ApiClient", () => {
it("should not throw an error if no constructor params are passed through", () => {
expect(() => new ApiClient()).not.toThrowError();
});

//@ts-expect-error
itShouldThrowIfInvalid("baseUrl", () => new ApiClient({ baseUrl: null }));
//@ts-expect-error
itShouldThrowIfInvalid("fetchDeviceCredentials", () => new ApiClient({ fetchDeviceCredentials: null }));
});

describe("request", () => {
Expand Down Expand Up @@ -48,9 +43,6 @@ describe("ApiClient", () => {
expect(() => apiClient.request("some-url", {})).toThrowError();
});

//@ts-expect-error
itShouldThrowIfInvalid("fetchDeviceCredentials", () => new ApiClient({ fetchDeviceCredentials: null }));

it("should run `this.fetchDeviceCredentials`", () => {
const url = "/some/path";
const fetchOptions = {};
Expand Down
3 changes: 0 additions & 3 deletions src/lib/api/test/parameterAssertUtils.spec.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
import assert from "@whereby/jslib-media/src/utils/assert";
import {
assertBoolean,
assertRoomName,
Expand All @@ -13,8 +12,6 @@ function forEachObject(object: Record<string, unknown>, func: (value: unknown, k
}
describe("parameterAssertUtils", () => {
function itShouldThrowForValues(testValues: Record<string, unknown>, test: (desc: string, value: unknown) => void) {
assert.ok(typeof test === "function", "test must be a function");

forEachObject(testValues, (value, descriptionOfValue) => {
it(`should throw for ${descriptionOfValue}`, () => {
test(descriptionOfValue, value);
Expand Down
7 changes: 0 additions & 7 deletions src/lib/utils/__tests__/debounce.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,13 +16,6 @@ describe("debounce", () => {
jest.clearAllMocks();
});

it("should throw if no function is provided", () => {
expect(() => {
// @ts-expect-error
debounce();
}).toThrow("fn<function> is required");
});

it("should set the timer with the specified delay", () => {
const delay = Math.floor(Math.random() * 2000);

Expand Down
4 changes: 0 additions & 4 deletions src/lib/utils/debounce.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
import assert from "@whereby/jslib-media/src/utils/assert";

interface Options {
delay?: number;
edges?: boolean;
Expand All @@ -21,8 +19,6 @@ interface DebouncedFunction {
* @returns {Function} Debounced function.
*/
export default function debounce(fn: DebouncedFunction, { delay = 500, edges }: Options = {}): DebouncedFunction {
assert.ok(typeof fn === "function", "fn<function> is required");

let timeout: NodeJS.Timeout | undefined;
let nCalls = 0;

Expand Down

0 comments on commit 7f4b4eb

Please sign in to comment.