Return type of the gsap.parseEase function.
Hi,
I just ran into a Type issue and thought it would be better to share.
The parseEase here has two return types: EaseFunction and EaseMap. The EaseMap is used when the function doesn’t have any input.
However, when you call parseEase without specifying an easing, like:
gsap.parseEase('Bounce');
gsap.parseEase('Power2');
gsap.parseEase('Back');
it actually returns what looks like an Ease object, which has easeIn, easeOut, and easeInOut properties, for example:
{ easeIn: ƒ, easeOut: ƒ, easeInOut: ƒ }
It seems to me that the parseEase function needs an override to support Ease in its return type.
If I understand your comment correctly, no, it shouldn't return an object that has easeIn, easeOut, and easeInOut methods. That's just for VERY old legacy support of the ancient syntax like Power2.inOut but we definitely don't want to encourage anyone to use that anymore. It should be considered deprecated long ago. Plus only a subset of eases would include those properties anyway. I'm curious why you'd want access to those - do you have an example of what you're trying to do? Maybe we can help with a different suggestion. The modern syntax is more like "power2.in" (string-based). The parseEase() method should just return a function that accepts a progress value (0-1) and returns the corresponding eased value.
In the codebase I’m working on, parseEase() is used to validate easing strings. If I want to simplify the code, it could look like this:
// Input can be either `Bounce.easeIn` or just `Bounce`.
const ease = gsap.parseEase(input);
if (!ease) throw new Error('First part missing'); // e.g. "Bounce"
if (!ease['easeIn']) throw new Error('Second part missing'); // e.g. ".easeIn" | ".easeOut"
And when I tried refactoring the function, I noticed that parseEase doesn’t have a return type that matches its actual response, when you pass only the first part of the easing, like: gsap.parseEase('Bounce'); it returns an object with this shape: { easeIn: ƒ, easeOut: ƒ, easeInOut: ƒ }.
I'm saying your code should NOT rely on the return EVER having .easeIn(), .easeOut(), or .easeInOut() methods. Why are you even tapping into those? It's a relic for an ancient syntax that won't be supported moving forward. It's from a pre-2019 era. Is there some valid reason you're trying to tap into those?
Hey, I’d like to work on this issue and help get it fixed. I’ve gone through the problem and I think I can contribute a solid solution. Please assign this to me if it’s available.