How do I extend a TypeScript class definition in a separate definition file? -


I have a JS library that has been typed in a manual that has an existing typeuscript definition file.

I want to use a plugin that enhances some items in the booklet with an additional function.

In the existing type-script definition file, the object is defined as classes rather than the interface.

For example

  Module L {Function Circle Marker (latlng: LatLng, options?: PathOptions) Announce: Cirkilmarker; Export Class Circle Marker Circle (Constant (latlong: Let's Launch, Options: Pathopaptations) Expands; SetLatLng (latlng: LatLng): Circlemaker; SetRadius (Radius: Number): Circlemaker; toGeoJSON (): Any;}} < / Code>  

If I try the second time in the second file and define it, then I get an error about "duplicate identifier circle marker".

  Module L {Export Square CircleM declare arker {bindLabel (name: string, option: any): circillmarker;}} This code makes sense because it is a class and there is no interface, but it does happen But is there any way to expand this class definition without changing the original definition file?  

The base definition file is definitely dragged through the newsgroup, so I have a strong desire to Do not make any changes in it That it will update the possibility of more weird / failing.

If you do not control the original definition file , And can not make adjustments to it, so unfortunately, what you are trying to do is not currently supported in type-scripts. There is a interface in the script, which is the only proper extension Allows because it is only a compass There is no time-lapse / syntax check and no run-time operation.

You can not increase the class in the type script with new functionality by using TypeScript (and code-completion / Intelligence as expected). You can definitely add work to the prototype class in the CircleMarker category, but they will be unavailable for intellance and compiling as long as you do not make a claim Will fail in Instead of using any , you should be able to use a interface with a type of confirmation:

  declare module L {export interface CircleMarkerEx {bindLabel (name: string, option: any): circillmarker; }}   

then:

  var cm = & lt; L. CrackMakerX & gt; Circle.bindLabel ("name", {});   

Thankfully, this does not add any run-time overheads, a bit of extra typing (reasonably intended!).

There are suggestions for such things on CodePlex, but they have not been implemented, even using the suggestions in the mix will not be completely straightforward, and for libraries Will not work well that were not completely written in the type of script (as it would be easy to code javascript, which can not be safely made for example with a mix)

Comments

Popular posts from this blog

Pass DB Connection parameters to a Kettle a.k.a PDI table Input step dynamically from Excel -

multithreading - PhantomJS-Node in a for Loop -

c++ - MATLAB .m file to .mex file using Matlab Compiler -