greensock / GSAP

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

error TS4025: Exported variable 'Tween' has or is using private name 'gsap.core.Tween'. #353

Closed naranjamecanica closed 4 years ago

naranjamecanica commented 4 years ago

I'm using a wrapper around your library in Typescript.

export const Tween = (target: {}, duration: number = 0, properties: gsap.TweenVars, settings?: gsap.TweenVars): gsap.core.Tween => {
  [...]    
  return gsap.to(target, vars);
}

When I export and generate declaration files for Typescript I get to following error:

error TS4025: Exported variable 'Tween' has or is using private name 'gsap.core.Tween'.

Is it possible to export a Tween const from the types like you do with TweenMax and TweenLite etc in gsap-core.d.ts?

Something like:

export class Tween extends gsap.core.Tween {}

OSUblake commented 4 years ago

Tween and Timeline aren't exported because we thought it might cause name conflicts with other libraries. https://github.com/greensock/GSAP/issues/318#issuecomment-553250162

There is a global type for a Tween, GSAPTween. But I don't know if that will help you as I'm not familiar with that error.

And you should be able to augment the types with your own d.ts file. Something like this.

declare module "gsap/gsap-core" {
  export class Tween extends gsap.core.Tween {}
}
naranjamecanica commented 4 years ago

Thanks the augmenting worked! Had some issues, but that was because my definition file was called gsap.d.ts.