castingtype-conversiontypescript

TypeScript: Convert a bool to string value


I am unable to convert a boolean to a string value in TypeScript.

I have been roaming through documentation and I could not find anything helpful. I have tried to use the toString() method but it does not seem to be implemented on bool.


Edit: I have almost no JavaScript knowledge and came to TypeScript with a C#/Java background.


Solution

  • Updated for comments!

    You can now use toString() to get a string value from a boolean type.

    var myBool: boolean = true;
    var myString: string = myBool.toString();
    console.log(myString);
    

    This outputs:

    "true"
    

    And has no errors or warnings.