Jump to content

TypeScript definition file for rStats.js


jmp909
 Share

Recommended Posts

Hi,

 

I'm trying to use rStats.js in TypeScript/Visual Studio Code but of course with no .d.ts file it's throwing errors

 

the issue is this is a constructor

this.rS = new rStats({ ... })

but this is essentially a method

this.rS('FPS').frame();

I was going to use a basic empy definition but I can't use rStats for both the module name and the class constructor.. not really sure how to implement it

 

thanks for any help.

J

 

(I can add this function rStats(obj:any):void {} , so it compiles at least.. and then make sure I embed rStats.js after game.js in my html file but that's a bit of a hack)

Link to comment
Share on other sites

I find tsc in VS Code is temperamental, sometimes it gives errors about not being able to find Classes and sometimes it doesn't

 

anyway this is currently working for me in my game class 

rS: anyrStats: any;

but i need a file to exist even though i dont include a /// <reference ..> to it.

 

rStats.d.ts

declare class rStats {    constructor(obj:any)}

otherwise it seems to moan about calling 

new rStats({ ... })

saying that it can't find rStats

 

:S

 

 

Link to comment
Share on other sites

I have to say that I am totally confused by that Syntax....

 

`this.rs("FPS").frame()`. 

 

In JavaScript I do not know what is happening!

 

So `let myStats = new rStats()` appears to return a function?? Then you call `myStats("property")` to return a value based on that property???  I am so confused!   Why did the author not just use getters/setters or even just properties? I am sure there is a reason! 

Anyway!

A cheap definition file could look like this to get rid of your error.  

 

rStats.d.ts

`declare var rStats: any;`

 

I was has hoping to throw a definition file together for you, but I just cannot understand what the code is doing :(

Link to comment
Share on other sites

Indeed! Here's the website by the way

http://spite.github.io/rstats/

I think I tried a definition like that but them the rS() code didn't work, hence defining them both as any in the class using it ... I'll take another look

Thanks

J

ps spent ages last night trying to allow game.iso to work for the isometric plugin then just found this and realised I had an out of date version! :S http://www.html5gamedevs.com/topic/8387-phaser-isometric-plugin/?p=56922 . Thanks again

Link to comment
Share on other sites

your method works thanks, i just need to define 

rS: any;

in my code

 

I'm going to try Visual Studio 2015 Community. Visual Studio Code seems a bit buggy although that could just be the tsc compiler

 

the path messes up occasionally. I'm referencing some 'typings' outside of my project folder and it doesn't like it sometimes (see screenshot)

<reference path="F:/typings/phaser/phaser.d.ts" />

post-16536-0-58336900-1443728183_thumb.j

Link to comment
Share on other sites

I'm going to try Visual Studio 2015 Community. Visual Studio Code seems a bit buggy although that could just be the tsc compiler

 

the path messes up occasionally. I'm referencing some 'typings' outside of my project folder and it doesn't like it sometimes (see screenshot)

<reference path="F:/typings/phaser/phaser.d.ts" />
Any chance you are using an old version of tsc? a year ago it only handled relative paths https://github.com/Microsoft/TypeScript/issues/800

*it looks like you should probably try and use a relative path though ;) (eg. so you can more easily move your project folder later)

Link to comment
Share on other sites

 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...