question

Fernando Rojas avatar image
Fernando Rojas asked

Typescript declarations files

Hi guys,

I would like to ask if there is any declaration files (d.ts) for using PlayFab with Typescript, i really want to have this files or even know how to create them from SDKGenerator maybe. I'm thinking of just declarating PlayFab by using declare PlayFab:any; or something... -> http://stackoverflow.com/questions/27417107/how-use-an-external-non-typescript-library-from-typescript-without-d-ts.

Thanks!

10 |1200

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.

brendan avatar image
brendan answered

We don't currently have declaration files for TypeScript, but we'll open a backlog item for the tools team to look at adding this to their process. It's certainly possible to use the non-d.ts route called out in the post you linked, though as stated in the posts on StackOverflow, there are some limitations when doing so, since you won't have the type info.

2 comments
10 |1200

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.

tmichael avatar image tmichael commented ·

I just want to add my 2 cents. I just switched to TypeScript as I was looking for some way to turn my CloudScript hairball into something maintainable.

TypeScript solves a number of problems with CloudScript beyond having to do less debugging:

- TypeScripts allows me to compile an entire codebase into a single file and control how that file is generated, as is necessary for CloudScript

- the GitHub addon partially solves the above point, but it still won't let me use folders. With TypeScript, I can use folders.

- TypeScript will allow you to strip comments out of of the compiled JS code, allowing me to insert verbose documentation without concern for CloudScript size limits.

- The declarations file that Joshua shared is phenomenal. No longer do I need to spend so much time on the API page.

- TypeScript allows me to define data structures for my own data, which I was starting to do in comment blocks but that's obviously terrible

- let

In my humble opinion, PlayFab would really benefit from embracing TypeScript at least enough to maintain a definition file and suggest it as an option in the CloudScript tutorial section.

1 Like 1 ·
Joshua Strunk avatar image Joshua Strunk tmichael commented ·

Hey @tmichael,

Thank you for the kind words about the declarations file I threw together, it means a lot. On your point of PlayFab maintaining a declaration file, the generator I wrote works as a target in their SDKGenerator, so all that would need to be done is pull request it in.

I have been hesitant though as it would be a first for the SDKGenerator.(All other targets produce Client,Server, and Admin APIs as out put this outputs none of them.). Also I have no idea how to write automatic test cases for a declarations file. There is also the issue that my declaration file has some best guess unofficially typed functions to acommatate for functions native to CloudScript that no longer have any official documentation.

(RIP http://cloudscript.playfab.com/)

All this is to say I really should have just done the pull request a while back and will be handling it tonight. It would be nice before I spend time on it though to get an official word on if this SDK target is appropriate.

0 Likes 0 ·
Joshua Strunk avatar image
Joshua Strunk answered

I actually have a generator written but its only for use with CloudScript currently. I could try and get it working with the javascript and node-sdk if I have time this weekend. Gist of the CloudScript d.ts

2 comments
10 |1200

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.

Joshua Strunk avatar image Joshua Strunk commented ·

A very late update on this. I took a look at the JavaScript and Node sdks a while back and found I didn't know enough about how either was used to write good declaration generators for them. Sorry I did not update here sooner.

In addition that declaration file is getting kind of old and I have recently found a bug. The string literal types all have an extra space at the end of them. EX. "USD " instead of "USD". I will just be trying to get the target pull requested into playfabs SDKGenrator instead of manually updating the declaration file in my posted gist. See my comment in the above answer for more info.

0 Likes 0 ·
1807605288 avatar image 1807605288 ♦ commented ·

Thanks for your submission Joshua! I've accepted it, and I'll try to get this out and officially published asap.
I'll be trying to squeeze TypeScript definitions in everywhere I can, using your code as a template, so stay tuned.

0 Likes 0 ·

Write an Answer

Hint: Notify or tag a user in this post by typing @username.

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.