Skip to content

Commit 921c50f

Browse files
committed
Replace == "string" with isString type-guard
1 parent baef8ee commit 921c50f

File tree

3 files changed

+6
-3
lines changed

3 files changed

+6
-3
lines changed

chartlets.js/src/lib/components/Select.tsx

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ import {
88
type SelectState,
99
} from "@/lib/types/state/component";
1010
import { type ComponentChangeHandler } from "@/lib/types/state/event";
11+
import { isString } from "@/lib/utils/isString";
1112

1213
export interface SelectProps extends Omit<SelectState, "type"> {
1314
onChange: ComponentChangeHandler;
@@ -64,7 +65,7 @@ export function Select({
6465
function normalizeSelectOption(
6566
option: SelectOption,
6667
): [string | number, string] {
67-
if (typeof option === "string") {
68+
if (isString(option)) {
6869
return [option, option];
6970
} else if (typeof option === "number") {
7071
return [option, option.toString()];

chartlets.js/src/lib/types/state/component.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import { type CSSProperties } from "react";
22
import { isObject } from "@/lib/utils/isObject";
33
import type { TopLevelSpec } from "vega-lite/src/spec";
4+
import { isString } from "@/lib/utils/isString";
45

56
export type ComponentType =
67
| "Box"
@@ -67,7 +68,7 @@ export interface TypographyState extends ContainerState {
6768
}
6869

6970
export function isComponentState(object: unknown): object is ComponentState {
70-
return isObject(object) && typeof object.type === "string";
71+
return isObject(object) && isString(object.type);
7172
}
7273

7374
export function isContainerState(object: unknown): object is ContainerState {

chartlets.js/src/lib/utils/objPath.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import { isObject } from "@/lib/utils/isObject";
2+
import { isString } from "@/lib/utils/isString";
23

34
export type ObjPath = (string | number)[];
45
export type ObjPathLike = ObjPath | string | number | undefined | null;
@@ -83,7 +84,7 @@ export function normalizeObjPath(pathLike: ObjPathLike): ObjPath {
8384
}
8485

8586
export function formatObjPath(objPath: ObjPathLike): string {
86-
if (typeof objPath === "string") {
87+
if (isString(objPath)) {
8788
return objPath;
8889
} else if (Array.isArray(objPath)) {
8990
return objPath

0 commit comments

Comments
 (0)