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

context.add typing issue #592

Closed
zakuk opened this issue Sep 5, 2024 · 1 comment
Closed

context.add typing issue #592

zakuk opened this issue Sep 5, 2024 · 1 comment

Comments

@zakuk
Copy link

zakuk commented Sep 5, 2024

I believe there is a typing issue with the Context interface in gsap-core.d.ts

interface Context {
    ...
    add(methodName: string, func: Function, scope?: Element | string | object): Function;
    add(func: Function, scope?: Element | string | object): void;
   ...
  }

As I understand it the second overload (adding to the context immediately) should return the 'return value' of the function passed to func i.e.

interface Context {
    ...
    add(methodName: string, func: Function, scope?: Element | string | object): Function;
-   add(func: Function, scope?: Element | string | object): void;
+   add<T extends Function>(func: T, scope?: Element | string | object): ReturnType<T>;
   ...
  }

Or at least thats the way it works for me :)

Zak.

@jackdoyle
Copy link
Member

Hm, I'm not a TypeScript expert, but wouldn't it be more like this?:

add<T extends (...args: any[]) => any>(func: T, scope?: Element | string | object): ReturnType<T>;

(your code was giving me a warning in my editor saying "TS2344: Type 'T' does not satisfy the constraint '(...args: any) => any'")

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

2 participants