I am creating a Typescript type definition for the Parse Javascript SDK . It is truly complete. The definition will work for review code and the cloud, but not in Node.
Using Parse on both sides on the client side and on the server side javascript
Search example:
var GameScore = Parse.Object.extend("GameScore");
Node Example:
var Parse = require('parse').Parse; var GameScore = Parse.Object.extend("GameScore");
Psueue type definition
declare module Parse { interface FacebookUtils { init(options?: any); } class Object { constructor(attributes?: any, options?: any); } module Cloud { interface FunctionResponse { success?: (response: HttpResponse) => void; error?: (response: HttpResponse) => void; } } } declare module "parse" { export = Parse; }
Using Parse with New Definition Creation
class GameScore extends Parse.Object {} var gameScore = new GameScore();
Everything will work well in Overview , because the Parse library is available worldwide.
Now in Node, everything will work fine if the import was like this:
var Parse = require("parse");
But the import actually looks like this:
var Parse = require("parse").Parse;
So, β. Parseβ at the end of the import may cause a problem when trying to access Parse.Object , because there is no access for β.Parseβ in the above definition.
So what I want to do is have one definition file that works for both the browser and Node. I was thinking about using an interface, but I donβt think that it will allow me to do extensions or implement when I want.
For instance:
declare module Parse { ... interface Parse { Object: Object; } } declare module "parse" { export = Parse; }
This would not allow me to extend Object , it is simply defined as a property in the Parse interface.
Any help would be great. Thanks.