function f1()
{
const v : string = String();
if(v) {alert("IF");} // OK
const b : boolean = v; // Type 'string' is not assignable to type 'boolean'.
if(b) {alert("BOOLEAN");}
}
f1();
现在我对这个问题的解决方案是双感叹号,但我闻到麻烦或者我错了:
const b : boolean = !!v; //OK
我用这个quide作为基础。