Skip to content

Static method inheritance #3334

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

Closed
MikeBall0 opened this issue Jun 1, 2015 · 7 comments
Closed

Static method inheritance #3334

MikeBall0 opened this issue Jun 1, 2015 · 7 comments
Labels
Question An issue which isn't directly actionable in code

Comments

@MikeBall0
Copy link

There's been some previous discussion about this https://typescript.codeplex.com/workitem/2047 but nothing seems to have come of it. I've got a real scenario where this is getting in the way.

I'm trying to make a .d.ts file for greensock's gsap TweenMax but I have an issue where TweenMax extends TweenLite, which has a static to(target:Object, duration:number, vars:Object):TweenLite, and TweenMax has a static to(target:Object, duration:number, vars:Object):TweenMax.

I can't use the TweenMax.to method because it's being hidden by the TweenLite.to, which makes most of the module useless.

If there's a way to make the definition work as intended I'd love to hear it, otherwise it would be nice to see this fixed.

@danquirk
Copy link
Member

danquirk commented Jun 2, 2015

For reference on why this behavior exists/persists, see:
#613
#2082

@MikeBall0
Copy link
Author

Yep, I understand why it exists but it would be really disappointing if there is no way to make a .d.ts that properly describes the behavior of TweenMax. I'm not suggesting a change to how Typescript handles inheriting static methods (at least I don't think I am) but it would be nice if there was a way to indicate that that's how the types work in existing Javascript code. I'm just interested in finishing the TweenMax.d.ts file so that I can start using it in my project.

@RyanCavanaugh
Copy link
Member

It's always possible to rewrite the classes in terms of their static and instance sides.

See "Class Decomposition" in the TypeScript Handbook http://www.typescriptlang.org/Handbook#writing-dts-files

@MikeBall0
Copy link
Author

Ah, that's a very interesting pattern that I wasn't aware of. I decomposed the class and now things are working, only thing is the autocomplete for TweenMax. shows that all the static methods belong to TweenMax_static, I couldn't figure out if there's a way to have the same name for both the static and instance sides, but it's very minor.

Thanks for the guidance, I'll definitely keep that in mind :)

@danquirk danquirk added the Question An issue which isn't directly actionable in code label Jun 2, 2015
@jeffreymorlan
Copy link
Contributor

declare class TweenLite {
    static to(target: Object, duration: number, vars: Object): TweenLite;
}
declare class TweenMax extends TweenLite {
    static to(target: Object, duration: number, vars: Object): TweenMax;
}

I don't see any error on this in either 1.4 or 1.5. I think the only way you could get an error on this to override is if there's something else that's making TweenMax not be assignable to TweenLite.

@MikeBall0
Copy link
Author

Hmm... I just tried it again and it seems to be working correctly (though it's yelling that the static side doesn't extend properly, I suspect that's from other problems at this point since a simple example like yours appears to work). That's strange because when I first opened this issue it was definitely insisting that TweenMax.to returned a TweenLite, contrary to the signature. I had multiple people look at it, so I think not crazy and I'm not sure why it's working now. Perhaps it was a project configuration issue on my end...

@mhegazy
Copy link
Contributor

mhegazy commented Jun 12, 2015

Looks like the issue has been handled. please reopen if there is any other issues.

@mhegazy mhegazy closed this as completed Jun 12, 2015
@microsoft microsoft locked and limited conversation to collaborators Jun 19, 2018
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Question An issue which isn't directly actionable in code
Projects
None yet
Development

No branches or pull requests

5 participants