Please, provide official support for TypeScript

Please, provide official support for TypeScript
0.0 0


I already know that there is no official TypeScript definitions for cocos2d-js.

But TypeScript gives us many advantages over JavaScript:

  • all object oriented paradigms like classes, interfaces, inheritance, etc.

  • strong typing checks

  • perfect auto complete

  • perfect refactoring

It’s so good that big and complex libraries are being developed using it (angularjs and reactjs).

That said, I’d like to ask cocos2d-js that you guys provide official TypeScript support.

It would benefit the community as a whole.

Thank you.


Please don’t. Not until TypeScript is completely and fully defined.


Strong type check and perfect auto complete sound amazing. Definitely solves my 2 biggest gripes with using JavaScript.


TypeScript already is very stable and mature.

I’m using it for quite some time and I didn’t have any problem. Each new release it gets better.

And you don’t have to take my experience with it as a good sign of its maturity.

Take in consideration that developers from angular and reactjs are using it as well as working closely with TypeScript developers to improve it even more.

Also, the beauty about TypeScript is that if you don’t want to use it you don’t need to.

There are 2 ways cocos developers can support TypeScript:

1 - they develop in TypeScript language.
It will easy there lives and won’t change anything to those users that don’t want to use TypeScript because when you build TypeScript source code ,it generates plain and valid JavaScript.

There’s nothing specific of TypeScript in the resulting JavaScript code.

2 - they can generate and maintain TypeScript definition files and keep developing in plain JavaScript.
In this way, the result for those that don’t want to use TypeScript

TypeScript definition files are nothing more than plain text files that have the definitions of classes and functions of your JavaScript code with some extra annotations in order to TypeScript compiler be aware of the expected type of each parameter.

So please don’t ask cocos developers not to officially support TypeScript because it won’t affect you in anyway if you prefer to keep writing your code in plain old JavaScript but it will impair the life of developers that prefer to use TypeScript.

Also, I know many people have prejudice to Microsoft but it’s really a great product. I used to have it too.

I’d like to invite you to watch this video and , in case you liked what you watched, give TypeScript a try, putting any negative feelings apart while testing it.

I’m pretty sure you like it too.

Thank you.

PS: I’d like to invite cocos developers to watch the video above to know a bit better about TypeScript. I’m pretty sure you will love it.


There was an attempt to create a typescript version of cocos2d-js, a lot of work still needs to be done though.


Yup, I definitely wish Cocos2d-JS had been written in TS, what a missed opportunity. Vanilla JS is gross (that’s my scientific opinion) and I have no interest in CoffeScript as it does not provide proper type definitions. Anyway, I started a repo with TS definitions a while ago, but it’s very incomplete and out of date:

I’m currently in the middle of writing type definitions for the Cocos Creator API in a separate branch, it’s about 20%-30% done. I will hopefully be done in the next two months or so, as I only put in a little time each day chipping away at this (some days I only have time to convert a single file before bed). Once the Cocos Creator API is done, I’ll start working on the Cocos2d-x API. I would assume that the overwhelming majority of those two codebases overlap, so that should go a lot more quickly.

Once I finish the Cocos Creator API though, I plan on sending it out to DefinitelyTyped. I’m sure there will be tons of little errors and things I’ve missed, but hopefully it will be a good starting place for the community to contribute and fix.


yeah, +1 for cocos official support for typescript !! :grinning:
TS really adds almost everything JS is missing.
With the benefits of autocompletion & intellisense, code becomes almost self-documented.
Your brain can focus on gameplay, instead of learning SDK function names, debugging typos or wrong types… :wink:


This was discussed a while ago, don’t know if there has been any progress on this or not.

Broken intellisense and autocomplete for Cocos2dx JS in Visual Studio Code


That would be amazing +1.
Sadly, I dont think they are going to do it. :frowning:


According to Cocos Creator roadmap. Type script support is in development phase for the Cocos Creator v1.5 release.


Maybe I’m wrong so please fix me but as I know TypeScript is compiled to JavaScript, so nothing stops you from using it right know.

If this is no possible, please explain why.


Technically, it is possible - but without any benefits of TypeScript. The whole point of TypeScript is in type safety, and when you’re using JS library in TS that doesn’t have type definitions, TS type checker just assumes that every type you’re getting from it is ‘any’ - which is not very helpful.

Nobody is saying that the whole Cocos2d should be rewritten in TS, but type definitions surely would help a lot.


I think they should use Emscripten to generate JS code in asm.js

Other game engines like Unity develope games for HTML5 and generate JS code in asm.js which runs at nearly native speed.

Using C++ we would be able to develop games for HTML5

It will improve performance and we will be able to use Class structure of C++


Just wanted to let everybody know that if you create a project with Cocos Creator, it outputs a pretty good set of TypeScript ambient declarations. This is of course for the Cocos Creator API (which I believe is based off cocos2d-x lite), but it’s a LOT better than nothing.

Just look for the file “creator.d.ts” in your project’s root directory. Even if you’re using cocos2d-x, I would check this out. I have not tried it myself though, I’ve only used it with Cocos Creator.

Also, I stumbled on this project for TypeScript support in Cocos Creator:

I’ve gotten some basic stuff working, the big drawback is that all of the documentation is in Chinese. But there are some code samples to look through, and it’s overall straightforward to get working.

Hopefully Cocos Creator v1.5 will have official TypeScript support, but this is a good stop-gap until it’s released.


see also:

Perhaps we can extract the core of the CocosTsGameMVC project out into a separate github repo and maintain it from there.


Note - after doing some testing on native JSB. I noticed a few incompatibilities with JSB - due to the inheritance model used by typescript compiler - it can largely go unnoticed when using a more compositional approach to development i.e not directly extending the cocos classes - i’m pushing a fix out very soon.


MVC code now works on JSB, Restructured so that we do not extend core cocos classes in typescript. Moved Node and Scene LifeCycle Extensions into dalste.mvc javascript IIFE package with corresponding typescript definitions.

Updated Factories to return Containers rather than cocos 2dx derived objects directly.

Will update articles accordingly very soon