2

Hello all and I have a strange error that I have already figured out the answer to, but I still don't understand why this is happening.

Okay, so my personal style is that I like to have a comment above the class that I have written to show people how to use the class and the methods that I have just created. I also like to explain what the classes purpose is. So on with the example:

/*
 This class is used to alert classes that the value has changed

 usages:
 export class SomeClassThatChangesValues{

     constructor(private calculatorAlert:CalculatorAlert){}

     doWork():void{
       this.calculatorAlert.add(10);
     }
 }


 export class SomeClassThatCares implements OnInit{
     constructor(private calculatorAlert:CalculatorAlert){}

     ngOnInit():void{
          this.calculatorAlert.valueChangedSubject.subscribe(v=> doWork2(v));
     }
 }
*/
export class CalculatorAlert
{
     valueChangedSubject:Subject= new Subject<number>();

     value:number=0;

     add(x:number):void{
         this.value += x;
         this.valueChangedSubject.next(this.value);
     }
}

The code above will throw an error when you add it to a module saying that there is an unexpected token > in the class file path.

I was able to fix this with changing the comment to:

    /* 
* This class is used to alert classes that the value has changed

* usages:
* export class SomeClassThatChangesValues{

*     constructor(private calculatorAlert:CalculatorAlert){}

*    doWork():void{
*       this.calculatorAlert.add(10);
*    }
*}


 *export class SomeClassThatCares implements OnInit{
 *   constructor(private calculatorAlert:CalculatorAlert){}

 *   ngOnInit():void{
 *        this.calculatorAlert.valueChangedSubject.subscribe(v=> doWork2(v));
 *   }
 *}
*/

The code above with adding the * fixes the issue, but my questions are why doesn't the first comment work? And, why do you have to add the * to make it work?

3xGuy
  • 2,235
  • 2
  • 29
  • 51
  • 1
    Possible duplicate of [Where is the syntax for TypeScript comments documented?](https://stackoverflow.com/questions/23072286/where-is-the-syntax-for-typescript-comments-documented) – ADreNaLiNe-DJ Jun 07 '18 at 13:52

0 Answers0