Reputation: 18791
I don't know if theres even a value in this. I'm just curious if it is possible?
if it's possible and what are the syntax for
initializing a const field in constructor in typescript?`
export class Gulpfile {
private dist: string;
private src: string;
constructor(){
const this.dist = './dist/';
this.src = './src'
}
}
Upvotes: 6
Views: 2658
Reputation: 31600
You can't have a constant class member.
Mainly because class members are always referenced by reference via the this keyword, and that reference can always be changed.
It's not supported in ES6 either.
Upvotes: 8