I am trying to create a .d.ts file for the KineticJS library. So far I have created the following interface declaration “kinect.d.ts”.(I cropped the code a bit for stackoverflow but I hope you get the idea)
module Kinetic {
interface Rect extends Shape {
constructor (config) ;
}
interface Shape extends Node
{
}
interface Node {
constructor (config);
clone(attrs): Node;
getAbsoluteOpacity(): number;
getAbsolutePosition(): any;
/*
other methods removed for stackoverflow example
*/
}
}
I hoped this would be enough to be able to create a Kinetic.Rect object in my app.ts file
/// <reference path="Kinetic.d.ts" />
var rect = new Kinetic.Rect({
x: 239,
y: 75,
width: 100,
height: 50
});
But it appears I have to do some extra work to use the KineticJS classes (like Rect) in TypeScript. Could anyone give some pointers on how to archive this?
Have you looked at the TypeScript example app at: http://typescript.codeplex.com/SourceControl/changeset/view/fe3bc0bfce1f#samples/imageboard/mongodb.ts
The code at this link creates a definition for the mongodb library. One difference between this and the Sohnee answer is that Sohnee implements the constructor in contrast to the following code snip from the link which is a stub class. I do not have enough reputation to ask Sohnee in the accepted answer why he implemented the constructor for an ambient class?