Skip to content

Commit 068d432

Browse files
committed
refactor: remove as any of file jsonUtils.test.ts
refactor: extract `DataType` as the return type of function `getDataType`
1 parent fe74dbe commit 068d432

File tree

2 files changed

+19
-12
lines changed

2 files changed

+19
-12
lines changed

client/src/utils/__tests__/jsonUtils.test.ts

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -149,17 +149,17 @@ describe("updateValueAtPath", () => {
149149
});
150150

151151
test("initializes an empty object when input is null/undefined and path starts with a string", () => {
152-
expect(updateValueAtPath(null as any, ["foo"], "bar")).toEqual({
152+
expect(updateValueAtPath(null, ["foo"], "bar")).toEqual({
153153
foo: "bar",
154154
});
155-
expect(updateValueAtPath(undefined as any, ["foo"], "bar")).toEqual({
155+
expect(updateValueAtPath(undefined, ["foo"], "bar")).toEqual({
156156
foo: "bar",
157157
});
158158
});
159159

160160
test("initializes an empty array when input is null/undefined and path starts with a number", () => {
161-
expect(updateValueAtPath(null as any, ["0"], "bar")).toEqual(["bar"]);
162-
expect(updateValueAtPath(undefined as any, ["0"], "bar")).toEqual(["bar"]);
161+
expect(updateValueAtPath(null, ["0"], "bar")).toEqual(["bar"]);
162+
expect(updateValueAtPath(undefined, ["0"], "bar")).toEqual(["bar"]);
163163
});
164164

165165
// Object update tests
@@ -293,10 +293,8 @@ describe("getValueAtPath", () => {
293293
});
294294

295295
test("returns default value when input is null/undefined", () => {
296-
expect(getValueAtPath(null as any, ["foo"], "default")).toBe("default");
297-
expect(getValueAtPath(undefined as any, ["foo"], "default")).toBe(
298-
"default",
299-
);
296+
expect(getValueAtPath(null, ["foo"], "default")).toBe("default");
297+
expect(getValueAtPath(undefined, ["foo"], "default")).toBe("default");
300298
});
301299

302300
test("handles array indices correctly", () => {

client/src/utils/jsonUtils.ts

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -25,10 +25,19 @@ export type JsonSchemaType = {
2525

2626
export type JsonObject = { [key: string]: JsonValue };
2727

28-
const typeofVariable = typeof "random variable";
29-
export function getDataType(
30-
value: JsonValue,
31-
): typeof typeofVariable | "array" | "null" {
28+
export type DataType =
29+
| "string"
30+
| "number"
31+
| "bigint"
32+
| "boolean"
33+
| "symbol"
34+
| "undefined"
35+
| "object"
36+
| "function"
37+
| "array"
38+
| "null";
39+
40+
export function getDataType(value: JsonValue): DataType {
3241
if (Array.isArray(value)) return "array";
3342
if (value === null) return "null";
3443
return typeof value;

0 commit comments

Comments
 (0)