refactor type assertions

This commit is contained in:
Sultan committed 2022-11-01 21:21:40 +03:00
1 parent b8b223538c
commit ebf59bf217
3 files changed
+9 -7

No files matched your search

@@ -54,9 +54,10 @@ export const useUnitSelect = ({
const [isOpen, setIsOpen] = useState(false);
const renderUnits = useMemo(
() =>
value &&
units
.filter((unit) => {
return isValid(property, toValue({ ...value, unit } as typeof value));
return isValid(property, toValue({ ...value, unit }));
})
.map((unit) => unitRenderMap.get(unit) ?? unit),
[units, property, value]
@@ -64,7 +65,11 @@ export const useUnitSelect = ({
const renderValue = value && unitRenderMap.get(value.unit);
if (value == undefined || renderValue === undefined) {
if (
value === undefined ||
renderUnits == undefined ||
renderValue === undefined
) {
return [isOpen, null];
}
@@ -3,7 +3,6 @@ import {
StyleValue,
StyleProperty,
toValue,
InvalidValue,
} from "@webstudio-is/react-sdk";
import type { InheritedStyle } from "./get-inherited-style";
import { isValid } from "./parse-css-value";
@@ -32,7 +31,7 @@ export const getFinalValue = ({
toValue({ ...currentValue, value: Math.abs(currentValue.value) })
) === false
) {
return { ...(currentValue as unknown as InvalidValue), type: "invalid" };
return { value: String(currentValue.value), type: "invalid" };
}
return currentValue;
};
@@ -2,9 +2,7 @@ import hyphenate from "hyphenate-style-name";
import { units } from "@webstudio-is/react-sdk";
import type { StyleProperty, StyleValue, Unit } from "@webstudio-is/react-sdk";
const unitRegex = new RegExp(
`${(units as unknown as string[]).concat("number").join("|")}`
);
const unitRegex = new RegExp(`${[...units, "number"].join("|")}`);
export const isValid = (property: string, value: string): boolean => {
// Only browsers with houdini api will provide validation for now