HiveBrain v1.2.0
Get Started
← Back to all entries
snippettypescriptCritical

TypeScript: Convert a bool to string value

Submitted by: @import:stackoverflow-api··
0
Viewed 0 times
typescriptboolconvertvaluestring

Problem

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

I have tried to use the toString() method but it does not seem to be implemented on bool.

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.

Code Snippets

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

Context

Stack Overflow Q#14774907, score: 210

Revisions (0)

No revisions yet.