2
Answers

typescript increases value for any datatype using pipe (|)

Photo of Rupesh Kahane

Rupesh Kahane

5y
709
1
I have declare a variable of type any. While assigning the values as per below & I am printing it on console, so its updating the value from 50 to 51.  I am using pipe (|) symbol Please help me & guide me if anything I am doing wrong.  let myVariable: any;   myVariable = "hello";   console.log("1 condition: " + myVariable);   myVariable = 20;   console.log("2 condition: " + myVariable);   myVariable = 50 | true | "false";   console.log("3 condition: " + myVariable);   Thanks

Answers (2)

0
Photo of Rajeesh Menoth
66 27.1k 2.7m 5y
Hi,
 
I am not sure what you are trying , But I don't know what is the use of "false" string false you have added after the pipe. The following code also should work and put instead of true +1 or +2 , etc.
  1. let myVariable: any;  
  2. myVariable = "hello";   
  3. console.log("1 condition: " + myVariable);   
  4. myVariable = 20;   
  5. console.log("2 condition: " + myVariable);  
  6. myVariable = 50 | true;   
  7. console.log("3 condition: " + myVariable);  
 
0
Photo of Laxmidhar Sahoo
NA 10.4k 55.5k 5y
hey desribe clearly pl.