I wonder why I get this compile error if I declare variable with var
or let
keywords? I mean, this goes well:
export class AppComponent {
refreshClickStream$: any;
constructor(){
}
While this brings the error:
export class AppComponent {
var refreshClickStream$: any;
constructor(){
}
Inside a class, TypeScript doesn't permit the declaration of class members with
var
let
const
(you can use readonly
on the property)
Further, inside of a class ALSO you'll be prohibited from declarating functions with
function
So you want this.
export class AppComponent {
a: string = "foo";
b: string = "bar";
foo(): void { }
constructor(){
}
}
Not,
export class AppComponent {
var a: string = "foo";
let b: string = "bar";
function foo(): void { }
constructor(){
}
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With