Extend definition for class?

Topics: General, Language Specification
Mar 24, 2014 at 9:46 AM
I'm trying to build definitions for Backbone.Stickit. That plugin extends Backbone.View and adds a method called stickit() to the View class.

The definitions for Backbone.View from DF is:
declare module Backbone {
    class View extends Events implements OptionalEvents {
The usage of the stickit plugin is:
var myView:Backbone.View = new Backbone.View();
Is there any way I can make this happen? Since View is a class I cannot re-declare it. Any pointers would be much appreciated!
Mar 24, 2014 at 3:48 PM
In TypeScript, while modules and interfaces are open-ended, classes are not. This means you won't be able to re-declare existing classes with new members.

That said, since you're using a declare module, the classes inside them are also declare classes. You can write declare classes as interfaces:
declare module Backbone {
    interface View extends Events, OptionalEvents { }
This would mean going and fixing up the previous declares to also use interfaces, but once you did you would have an open-ended View declaration.
Marked as answer by eirikhm on 3/25/2014 at 1:05 AM
Mar 25, 2014 at 8:05 AM
I suspected that was the only solution. Thanks for the help!
Mar 25, 2014 at 9:16 AM
There is an open request to make classes open ended like interfaces : http://typescript.codeplex.com/workitem/917 this will make it easier for people to write good definitions for existing JavaScript libraries.