Skip to content

Commit 5297b39

Browse files
committed
improve error messaging
1 parent f79425f commit 5297b39

File tree

1 file changed

+15
-2
lines changed

1 file changed

+15
-2
lines changed

src/index.ts

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -106,7 +106,7 @@ function animate(
106106
// or numbers, return an error
107107
throw Error(
108108
`Keyframe ${curKeyNum} and ${curKeyNum +
109-
1} must be of the same dimension. Received ${getType(
109+
1} values must be of the same type. Received ${getType(
110110
curKey.keyValue
111111
)} and ${getType(nextKey.keyValue)}`
112112
);
@@ -300,8 +300,21 @@ function animate(
300300
easeOut = 33,
301301
velocityIn = 0,
302302
velocityOut = 0,
303+
...nonValidKeyProps
303304
} = key;
304-
305+
const invalidPropNames = Object.getOwnPropertyNames(nonValidKeyProps);
306+
if (invalidPropNames.length !== 0) {
307+
const triedTime = invalidPropNames.indexOf('time') > -1;
308+
const triedValue = invalidPropNames.indexOf('value') > -1;
309+
// Extra parameters were added to a keyframe
310+
throw new Error(
311+
`Unexpected property on keyframe ${index}: ${invalidPropNames.join(
312+
', '
313+
)}${triedTime ? `. Did you mean "keyTime"?` : ``}${
314+
triedValue ? `. Did you mean "keyValue"?` : ``
315+
}`
316+
);
317+
}
305318
// Alert the user if an eKey is missing
306319
// the required arguments
307320
if (keyTime == null) {

0 commit comments

Comments
 (0)