greensock / GSAP

GSAP (GreenSock Animation Platform), a JavaScript animation library for the modern web
https://gsap.com
19.84k stars 1.72k forks source link

GSAP 3.0.2 TypeScript no longer compiles #342

Closed n8sabes closed 4 years ago

n8sabes commented 4 years ago

3.0.2 release breaks TypeScript projects. Is there a GSAP 3.x TypeScript accurate reference / tutorial / example?

Worked in 2.x:

import TweenMax from "gsap/TweenMaxBase";
const tweenRef: MutableRefObject<TweenMax | null> = useRef(null);

Worked in 3.0.1:

import gsap from "gsap";
const tweenRef: MutableRefObject<GSAPStatic.Tween | null> = useRef(null);

3.0.2 ?????

import gsap, {Tween} from "gsap";
const tweenRef: MutableRefObject<Tween | null> = useRef(null);

3.0.2 Assigning result from gsap.to() to the ref.current generates this error: Type 'Tween' is not assignable to type 'TweenLite | TweenMax | null'. Type 'Tween' is missing the following properties from type 'TweenMax': updateTo, target, timelinets(

3.0.2 type defines the result from gsap.to as a <core.Tween>

n8sabes commented 4 years ago

There was a lingering @types/gsap in the project that needed to be removed. For some reason it didn't cause an issue in 3.0.1 but does in 3.0.2.

This works:

import gsap from "gsap";
const tweenRef: MutableRefObject<GSAPAnimation | null> = useRef(null);
OSUblake commented 4 years ago

Hi @n8sabes

It looks like you found some of the global types that have been added to 3.0.2. GSAPAnimation is the base class that GSAPTween and GSAPTimeline extend. If it's supposed to be a tween, you're probably better off doing this as Tween has some properties/methods that don't exist on Animation.

const tweenRef: MutableRefObject<GSAPTween | null> = useRef(null);

I plan on documenting all those types so people don't run into problems like this.

n8sabes commented 4 years ago

Thank you, @OSUblake.