“投放”与转化不同。在这种情况下,window.location.hash将自动将数字转换为字符串。但是为了避免TypeScript编译错误,您可以自己进行字符串转换:
window.location.hash = ""+page_number; 
window.location.hash = String(page_number); 
如果您不希望在page_numberis null或时引发错误,那么这些转换是理想的选择undefined。而page_number.toString()和page_number.toLocaleString()将在page_numberis null或时抛出undefined。
当您只需要强制转换而不是转换时,这就是在TypeScript中强制转换为字符串的方法:
window.location.hash = <string>page_number; 
// or 
window.location.hash = page_number as string;
该<string>或as string投注解告诉打字稿编译器把page_number在编译时间的字符串; 它不会在运行时转换。  
但是,编译器会抱怨您不能为字符串分配数字。您必须先将转换为<any>,然后再转换为<string>:
window.location.hash = <string><any>page_number;
// or
window.location.hash = page_number as any as string;
因此,转换将更容易,因为它可以在运行时和编译时处理类型:
window.location.hash = String(page_number); 
(感谢@RuslanPolutsygan解决了字符串转换问题。)
               
              
page_number是null这将设置window.location.hash为*字符串"null"。(我更喜欢一个错误:D)。