refactor: remove as any of file jsonUtils.test.ts

refactor: extract `DataType` as the return type of function `getDataType`
This commit is contained in:
yushengchen
2025-04-09 09:24:42 +08:00
parent fe74dbea74
commit 068d43226f
2 changed files with 19 additions and 12 deletions

View File

@@ -25,10 +25,19 @@ export type JsonSchemaType = {
export type JsonObject = { [key: string]: JsonValue };
const typeofVariable = typeof "random variable";
export function getDataType(
value: JsonValue,
): typeof typeofVariable | "array" | "null" {
export type DataType =
| "string"
| "number"
| "bigint"
| "boolean"
| "symbol"
| "undefined"
| "object"
| "function"
| "array"
| "null";
export function getDataType(value: JsonValue): DataType {
if (Array.isArray(value)) return "array";
if (value === null) return "null";
return typeof value;