Jump to content
GreenSock

DimSum

TypeScript error with the ScrollTrigger + Lottie sample code

Recommended Posts

Hi all,

I'm trying to use the helper function in the docs to build a scroll based lottie animation in my project. However, I can't figure out how to solve this error. Does anyone have any ideas? thanks very much!

 

image.thumb.png.420a811d8d168a8e6b173e0324b42d4d.png

Link to comment
Share on other sites

It's pretty tough to troubleshoot without a minimal demo - Would you please provide a very simple CodePen or CodeSandbox that demonstrates the issue? 

 

Please don't include your whole project. Just the lottie animation and the GSAP code is best (avoid frameworks if possible). See if you can recreate the issue with as few dependancies as possible. If not, incrementally add code bit by bit until it breaks. Usually people solve their own issues during this process! If not, then at least we have a reduced test case which greatly increases your chances of getting a relevant answer.

 

Here's a starter CodePen that loads all the plugins. Just click "fork" at the bottom right and make your minimal demo

See the Pen aYYOdN by GreenSock (@GreenSock) on CodePen

 

Once we see an isolated demo, we'll do our best to jump in and help with your GSAP-specific questions. 

Link to comment
Share on other sites

Thanks for the tips! Unfortunately it's kind of difficult for me to isolate it in a code sample. I'll still try to do it, but in the meantime, I can provide some more context.

 

The code is working fine in the browser, no console error whatsoever. The TypeScript linting error is only in the code editor and I cannot deploy my code without resolving it.

 

I'm using ReactJS server side rendering + TypeScript. gsap is being loaded async in a client component.

 

From what I understand, this lottie.loadAnimation returns an AnimationItem.

 

animation = lottie.loadAnimation({
  ...
});

 

Then it's creating a frameTween here

 

animation.addEventListener("DOMLoaded", function() {
  let createTween = function() {
    animation.frameTween = gsap.to(playhead, {
      ...
    });
    ...
  };
  ...    
});

 

But when looking at the type AnimationItem definition in index.d.ts, there's no frameTween

 

export type AnimationItem = {
    name: string;
    isLoaded: boolean;
    currentFrame: number;
    currentRawFrame: number;
    firstFrame: number;
    totalFrames: number;
    frameRate: number;
    frameMult: number;
    playSpeed: number;
    playDirection: number;
    playCount: number;
    isPaused: boolean;
    autoplay: boolean;
    loop: boolean | number;
    renderer: any;
    animationID: string;
    assetsPath: string;
    timeCompleted: number;
    segmentPos: number;
    isSubframeEnabled: boolean;
    segments: AnimationSegment | AnimationSegment[];
    play(name?: string): void;
    stop(name?: string): void;
    togglePause(name?: string): void;
    destroy(name?: string): void;
    pause(name?: string): void;
    goToAndStop(value: number | string, isFrame?: boolean, name?: string): void;
    goToAndPlay(value: number | string, isFrame?: boolean, name?: string): void;
    includeLayers(data: any): void;
    setSegment(init: number, end: number): void;
    resetSegments(forceFlag: boolean): void;
    hide(): void;
    show(): void;
    resize(): void;
    setSpeed(speed: number): void;
    setDirection(direction: AnimationDirection): void;
    setLoop(isLooping: boolean): void;
    playSegments(segments: AnimationSegment | AnimationSegment[], forceFlag?: boolean): void;
    setSubframe(useSubFrames: boolean): void;
    getDuration(inFrames?: boolean): number;
    triggerEvent<T = any>(name: AnimationEventName, args: T): void;
    addEventListener<T = any>(name: AnimationEventName, callback: AnimationEventCallback<T>): () => void;
    removeEventListener<T = any>(name: AnimationEventName, callback?: AnimationEventCallback<T>): void;
}

I think this is causing the error but I don't know how to fix it...

Link to comment
Share on other sites

I think that was just a way to allow you to access the GSAP tween, that's all. I'm not a TypeScript pro - you may need to adjust your definitions if that's causing a problem. It's just a helper function, after all, it's not intended to be a full TypeScript-enabled tool :)

  • Thanks 1
Link to comment
Share on other sites

That definition is in the lottie-web package. I'm not too knowledgeable with TypeScript either. I tried to extend the type but it's throwing more errors :sad: I just tried using Chris Gannon's code and TypeScript is not complaining now :lol:

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
  • Recently Browsing   0 members

    • No registered users viewing this page.
×