Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Typescript @types #46

Open
tomgallagher opened this issue Dec 9, 2020 · 9 comments
Open

Typescript @types #46

tomgallagher opened this issue Dec 9, 2020 · 9 comments

Comments

@tomgallagher
Copy link

Hey

Thanks for the library - helped me out of a tight spot.

Getting this error when compiling with Typescript.

node_modules/@types/gifencoder/index.d.ts:22:19 - error TS2304: Cannot find name 'CanvasRenderingContext2D'.

22 addFrame(ctx: CanvasRenderingContext2D): void;

Any thoughts?

Tom

@VannaDii
Copy link

VannaDii commented Dec 8, 2021

@tomgallagher, are you still having this issue or did you find a way around it?

@VannaDii
Copy link

VannaDii commented Dec 8, 2021

For anyone else who stumbles into this when running tsc fails for them:

Update your tsconfig.json to include DOM as a lib. Why does this work? Because CanvasRenderingContext2D is a globally available type in the DOM and including this library allows TypeScript to resolve the type reference.

// ... other config ...

    "lib": [
      "DOM",
      // ... others libs
    ],

// ... other config ...

@tomgallagher
Copy link
Author

@GioCirque - I think I just built that file in JS in the end. Can't remember. But you can close the issue. Thanks for reply.

@VannaDii
Copy link

VannaDii commented Dec 8, 2021

I also had to cast a Buffer to any because, it seems, the types are defined for web only, and the addFrame signature only takes a CanvasRenderingContext2D.

@kavimaluskam
Copy link

@GioCirque I am trying to use this project in typescript but even the new Gifencoder method failed.
Do you any clue how to get that working?

@VannaDii
Copy link

You can check out my full, working TypeScript implementation over here. I recently started seeing some interesting outputs so I'm exploring a new implementation. I'll let you know if anything comes from it.

@VannaDii
Copy link

!!!WARNING !!!
DO NOT assign your GIFEncoder instance to undefined after calling finish(). I've observed this clearing the entire GIF on disk and leaving a nearly empty file with just a GIF89a header inside.

@VannaDii
Copy link

@kavimaluskam If you're interested, you can also see how I'm adding images via context (maybe overkill) in the snapshotEvent function and the simple finalization in the maybeFinalizeGif function

@kavimaluskam
Copy link

Thank you so much @GioCirque , it definitely helped. 🚀

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants