I am getting syntax error on line “static instance:SingletonService;”.
This is the working code with IONIC 2.0.0-beta.19, but it gives error after upgrading to latest build IONIC 2.0.0-beta.25.
@iignatov Thanks a lot.
But all my files are .js files. So I have rewrite code again in typescript?
I have not much experience in TypeScript.
Is there any way to use same .js files ?
Actually it seems that your code is already in TypeScript (or at least the one that you pasted), so you will have to convert it to JavaScript. If you want to use the current code in a JavaScript project (acknowledging that it’s an invalid JavaScript code) then you have to made modifications to your build process to allow it. Check out the linked post for more details on how exactly to do it:
@rapropos That’s what I also thought at first. However taking into consideration that he doesn’t have much experience with TypeScript and that the state of the other code is unknown (i.e. only TypeScript or a mix of TypeScript and JavaScript) it’s hard to tell. While I personally prefer TypeScript, there’s definitely a lot to be desired in terms of library support (e.g. there are still plenty of missing or outdated type definitions).
@mohammed2raja I should say that I agree with @rapropos that you should consider if it’s not easier to switch the project to TypeScript. If the code is already mostly in TypeScript then it might be easier to go this way. TypeScript is not that hard - here’s a good article about it. And it might be a good investment because Ionic 2 is moving in this direction. Also I would recommend you to weigh your priorities and constraints and decide which option would be the better one in your case.
Fair enough. Since TypeScript is largely a superset of JavaScript, though, I still think that tsc is going to do a better job of coping with a mishmash of TypeScript and JavaScript than would somebody without much TS knowledge trying to transcode it down to JS by hand.
I agree that there shouldn’t be any problems with the JavaScript code itself - I was actually thinking about the Angular/Ionic specifics for JavaScript (e.g. static get parameters() for dependency injection, etc). However, I guess that when the code worked well while the TypeScript compiler was used for transpilation under the hood, it might work fine this way (or with minimal changes) in TypeScript too. Then it maybe depends only on the support for TS projects of the libraries used in the project (e.g. Auth0 doesn’t play well with TS).