Gulp Build gives error While Type cast mentioned for any variable

Hi,

Tried creating Services and use it on component , but ionic 2 seems not understanding the Type while declaring any variable and giving error "Unexpected Token on line *"
For ex :
export class Login {
id:number;
username:string;
password:string;
}

Declaring this class like this and use it any component it says Unexpected Token on Line 2 , 3 ,4 and if you remove all Type of the variable it gives error “Missing class properties transform. while parsing file”

Same Applies while initiating services in the constructor of a Component class
For Ex :
constructor(private _router : Router,private _loginservice: LoginService){} >> Its gaves the same Unexpected token error

As per Angular 2 this is the correct Syntax which I am using and worked properly if I use only Angular 2 but not on Ionic 2

Thanks,
Snehasis Mohapatra

I guess that you’re trying to use types in a JavaScript project. Types and class properties are valid only in TypeScript projects. For more details check out the following post:

1 Like

Thanks for the reply.

So Is that mean Ionic 2 is not using TypeScript of Angular 2 ?

Is it using Javascript version of Angular 2 which is not Documented yet ?

Is there a possibility that IONIC 2 will come up with TypeScript Coding Style and build using the same ?

Thanks

Ionic supports both TypeScript and JavaScript projects. When you’re creating a new project you can choose if it should be in TypeScript or JavaScript. Currently JavaScript is the default (however this is going to change) so if you haven’t specified explicitly that you want a TypeScript project then your project is in JavaScript.

To start a new TypeScript project type (note the --ts - it indicates that you want TypeScript):

ionic start MyNewApp --v2 --ts

For more information check out the Ionic 2 Getting Started Tutorial.

1 Like