Skip to content

Commit 9527884

Browse files
committed
fix: type error
1 parent 38b731e commit 9527884

File tree

1 file changed

+22
-23
lines changed

1 file changed

+22
-23
lines changed

src/helpers/parseElementTransitionEffects.ts

Lines changed: 22 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { ScrollAxis, ValidScrollAxis } from '..';
1+
import { CSSEffect, ScrollAxis, ValidScrollAxis } from '..';
22
import {
33
ParsedValueEffect,
44
ValidCSSEffects,
@@ -37,14 +37,14 @@ export function parseElementTransitionEffects(
3737
const parsedEffects: { [key: string]: ParsedValueEffect } = {};
3838

3939
PARALLAX_EFFECTS.forEach((key: keyof typeof ValidCSSEffects) => {
40-
const value = props?.[key];
4140
const defaultValue: AllValidUnits = MAP_EFFECT_TO_DEFAULT_UNIT[key];
4241

4342
// If the provided type is a number, this must be the speed prop
4443
// in which case we need to construct the proper translate config
45-
if (typeof value === 'number') {
46-
const startSpeed = `${(props.speed || 0) * 10}px`;
47-
const endSpeed = `${(props.speed || 0) * -10}px`;
44+
if (typeof props?.[key] === 'number') {
45+
const value = props?.[key] as number;
46+
const startSpeed = `${(value || 0) * 10}px`;
47+
const endSpeed = `${(value || 0) * -10}px`;
4848

4949
const startParsed = parseValueAndUnit(startSpeed);
5050
const endParsed = parseValueAndUnit(endSpeed);
@@ -67,28 +67,27 @@ export function parseElementTransitionEffects(
6767
}
6868

6969
// The rest are standard effect being parsed
70-
const shouldParseEffect =
71-
Array.isArray(value) &&
72-
typeof value?.[0] !== 'undefined' &&
73-
typeof value?.[1] !== 'undefined';
70+
if (Array.isArray(props?.[key])) {
71+
const value = props?.[key] as CSSEffect;
7472

75-
if (shouldParseEffect) {
76-
const startParsed = parseValueAndUnit(value?.[0], defaultValue);
77-
const endParsed = parseValueAndUnit(value?.[1], defaultValue);
73+
if (typeof value[0] !== 'undefined' && typeof value[1] !== 'undefined') {
74+
const startParsed = parseValueAndUnit(value?.[0], defaultValue);
75+
const endParsed = parseValueAndUnit(value?.[1], defaultValue);
7876

79-
const easing = createEasingFunction(value?.[2]);
77+
const easing = createEasingFunction(value?.[2]);
8078

81-
parsedEffects[key] = {
82-
start: startParsed.value,
83-
end: endParsed.value,
84-
unit: startParsed.unit,
85-
easing,
86-
};
79+
parsedEffects[key] = {
80+
start: startParsed.value,
81+
end: endParsed.value,
82+
unit: startParsed.unit,
83+
easing,
84+
};
8785

88-
if (startParsed.unit !== endParsed.unit) {
89-
throw new Error(
90-
'Must provide matching units for the min and max offset values of each axis.'
91-
);
86+
if (startParsed.unit !== endParsed.unit) {
87+
throw new Error(
88+
'Must provide matching units for the min and max offset values of each axis.'
89+
);
90+
}
9291
}
9392
}
9493
});

0 commit comments

Comments
 (0)