Sign In Register

How can we help you today?

Start a new topic

TypeScript Definitions For Cloud Code

I've generated a set of TypeScript type definitions for the Cloud Code API.

Kudos to the GameSparks team for having such consistent and parseable documentation.

1 person has this question

@Mislav Zlatar

I am interested for that, my testing process is very slow.

Can you show the work when you finish?

Sure I can share when I finish. Are you interested in specific part or whole arhitecture?



@Mislav Zlatar

I think show the whole architecture is better, there may be others who need it

Thanks in advance!

I've generated some updated TypeScript type defs to include the new gamedataservice api.

If anyone is interested, check it out and let me know if there are any issues

First sorry for recreating the wheel.


I recreated the Cloud Code definition file from the web page and added all the document content.

If you need more code documentation, you can try my version.


P.S. does not include Request API

So you use this with an external editor with TS, build it (outputs a CS-parsed version) then push to github, and it reflects in GS as normal cloud code? With this, can I also use ES6 and it'll parse to CS?

>> So you use this with an external editor with TS

Yes. I use the external editor is VS Code.

>> build it (outputs a CS-parsed version)

Yes. In fact, to build twice, the first time TypeScript build to JavaScript(command: tsc), the second time JavaScript build to Cloud Code(command: node gscc).

>> then push to github

You can try, but I just upload with zip file.

>> and it reflects in GS as normal cloud code? 


>> With this, can I also use ES6 and it'll parse to CS?

No. Just can use ES5, this is my tsconfig settings:


"compilerOptions": {

"target": "es5", /* Specify ECMAScript target version: 'ES3' (default), 'ES5', 'ES2015', 'ES2016', 'ES2017', or 'ESNEXT'. */

"module": "commonjs", /* Specify module code generation: 'none', commonjs', 'amd', 'system', 'umd', 'es2015', or 'ESNext'. */

"lib": ["es5", "es2015"], /* Specify library files to be included in the compilation: */

"outDir": "./dist/", /* Redirect output structure to the directory. */

"removeComments": true, /* Do not emit comments to output. */

"strict": true, /* Enable all strict type-checking options. */

"baseUrl": "./modules/" /* Base directory to resolve non-absolute module names. */


@ Johnson Chu

Ok, but I will need few weeks, dont have time right now.




@Johnson Chu

I am also developing CLoud with TS and VSCode.

I have downloaded Sparkrequests from

And when I use it like this:


private createMatchRequest(skill : number) : SparkRequests.MatchmakingRequest {
        const request = new SparkRequests.MatchmakingRequest();
        request.skill = skill;
        return request;

It has no compilation errors but when I run test I get error :
SparkRequests is not defined.


@Mislav Zlatar

1. Do you have to use this command to compile?

tsc; node gscc

2. Can you show your compiled js code?

Actually it compiles OK with that command but error happens when I run Mocha unit tests with npm run test

Hi Mislav,

Did you include the real javascript sdk to your Mocha configuration?

It's possible to run unit tests against a real GameSparks instance, but I would advise you to create a mock implementation.

Best regards

Yep I am successfully mocked whole GameSparks until this but Spark and SparkPlayerMock typings are defined as interfaces while this SparkRequests are namespaces..

My workaround for now is that I have created my own class like this:


// tslint:disable-next-line:no-namespace
export namespace SparkRequests {

    export class MatchmakingRequest  {
        public matchShortCode : string;
        public skill : number;
        // tslint:disable-next-line:no-empty
        public Send() : void {}
        // tslint:disable-next-line:no-empty
        public SendAs(playerId : string) : void {}

 And when I run my build Grunt.js script before ts compilation I am commenting out line


import { SparkRequests } from "../spark-requests/MatchMakingRequest";

 and after build I am uncommenting it again so I can unit test it.

It's ugly, I am searching for bettrer way.


@Mislav Zlatar

This may seem like a problem with my definition file, when I confirm the problem, I will update to gamesparks-request-api-typings.

Thanks, please let me know when you finish to test it out,


Login to post a comment