function toBoolean(something: any): boolean { return something as boolean; } cc.log(toBoolean(1));
上面代码输出还是1,something还是number类型,类型断言并没有什么用
function toBoolean(something: any): boolean { return Boolean(something); } cc.log(toBoolean(1));
若要进行类型转换,需要直接调用类型转换的方法Boolean()