在Typescript中从数字转换为字符串的最佳方法(如果有)是什么?
var page_number:number = 3;
window.location.hash = page_number;
在这种情况下,编译器抛出错误:
类型“number”不能赋值给类型“string”
因为location.hash
是一个字符串。
window.location.hash = ""+page_number; //casting using "" literal
window.location.hash = String(number); //casting creating using the String() function
那么哪种方法更好呢?
https://stackoverflow.com/questions/32554624
复制相似问题