First, this question first arose after working with Three.js where I tried/trying to build interfaces for the library for my own sake.
Anyways, lets say we have the JS code:
var foo = new THREE.Vector3(0,0,0);
In TypeScript you could represent the THREE object as:
interface IThreeJS {
Vector3(x: number, y: number, z: number): any;
}
declare var THREE: IThreeJS;
However as you can see we have ': any' returning from Vector3. If I create a IVector3 interface and try doing 'new THREE.Vector3(0,0,0): IVector3' we get a 'new expression on valid on constructors'. Hence having to return 'any'
Right now the only alternative is to have the Vector3 object off of IThreeJS return 'any' and do:
var foo: IVector3 = new THREE.Vector3(0,0,0);
So, is there anyway to have my IThreeJS interface's Vector3 method have a constructor AND return an IVector3?
You can declare classes and modules too:
declare module THREE {
export class Vector3 {
constructor(x: number, y: number, z: number);
}
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With