TypeScript: Convert a bool to string value

This is either a bug in TypeScript or a concious design decision, but you can work around it using:

var myBool: bool = true;
var myString: string = String(myBool);
alert(myString);

In JavaScript booleans override the toString method, which is available on any Object (pretty much everything in JavaScript inherits from Object), so…

var myString: string = myBool.toString();

… should probably be valid.

There is also another work around for this, but I personally find it a bit nasty:

var myBool: bool = true;
var myString: string = <string><any> myBool;
alert(myString);

Leave a Comment

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)