cocos2d / cocos2d-html5

Cocos2d for Web Browsers. Built using JavaScript.
https://www.cocos.com
3.07k stars 902 forks source link

Add TypeScript definitions (To enable VSCode intellisense) #3390

Open sachingarg05 opened 8 years ago

sachingarg05 commented 8 years ago

As discussed with both @minggo and Visual Studio Code team, only way to enable VSCode intellisense for Cocos2d-html5 is to add TypeScript definitions for it. Maybe like it was done for the CocosCreator engine by adding comments in code which are parsed to generate TypeScript definitions.

It will be great if we can have the same for cocos2d-html5 also. We are using webstorm currently but it is not free and 'very' heavy on ram usage. Also, JSB debugging works great with VSCode using Cocos2dx plugin.

References: https://github.com/Microsoft/vscode/issues/9391 https://github.com/Microsoft/TypeScript/issues/10142 http://discuss.cocos2d-x.org/t/cocos2d-x-v3-12-released/30641/51 http://discuss.cocos2d-x.org/t/broken-intellisense-and-autocomplete-for-cocos2dx-js-in-visual-studio-code/30738

ntrrgc commented 8 years ago

This would be easier if there was a tool to generate TypeScript definitions from JSDoc comments.

ronyeh commented 8 years ago

I would vote for moving the cocos2d-html5 codebase to TypeScript.

If the project maintainers are interested in doing this, I could even donate a little bit of time helping out during the transition.

I actually don't think the transition would be too bad.

1) Rename all cocos2d .js files to .ts. Do not change any lines of code. (TS is a superset of JS after all.)

2) Use vscode or the tsc compiler to compile all .ts files back down to .js files (es5). The tsconfig.json file would be very simple (7 lines).

3) Done! Of course, this would provide very little help with vscode intellisense. However, the community can slowly submit pull requests to add typing information to the function parameters and return values. This will help improve the intellisense/autocomplete over time.

Remember, TS is just JS (plus some optional type annotations). We can do this incrementally, but it will have a huge boost of productivity for cocos2d users!