Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to initialize a const field in constructor in typescript?

I don't know if theres even a value in this. I'm just curious if it is possible?

Question:

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'
  }
 }
like image 822
Armeen Harwood Avatar asked May 22 '16 06:05

Armeen Harwood


1 Answers

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.

like image 63
toskv Avatar answered Sep 30 '22 18:09

toskv