{"id":28359,"date":"2024-11-24T12:44:05","date_gmt":"2024-11-24T04:44:05","guid":{"rendered":"https:\/\/fwq.ai\/blog\/28359\/"},"modified":"2024-11-24T12:44:05","modified_gmt":"2024-11-24T04:44:05","slug":"typescript-%e7%b1%bb%e5%9e%8b%e8%bd%ac%e6%8d%a2%e7%9a%84%e5%9b%b0%e6%83%91%ef%bc%9a%e4%b8%ba%e4%bb%80%e4%b9%88%e4%bd%bf%e7%94%a8-as-number-%e4%bb%8d%e7%84%b6%e6%98%af%e5%ad%97%e7%ac%a6%e4%b8%b2","status":"publish","type":"post","link":"https:\/\/fwq.ai\/blog\/28359\/","title":{"rendered":"TypeScript \u7c7b\u578b\u8f6c\u6362\u7684\u56f0\u60d1\uff1a\u4e3a\u4ec0\u4e48\u4f7f\u7528 as number \u4ecd\u7136\u662f\u5b57\u7b26\u4e32\uff1f"},"content":{"rendered":"<p><img decoding=\"async\" src=\"https:\/\/img.php.cn\/upload\/article\/001\/246\/273\/173156886323806.jpg\" class=\"aligncenter\" title=\"TypeScript \u7c7b\u578b\u8f6c\u6362\u7684\u56f0\u60d1\uff1a\u4e3a\u4ec0\u4e48\u4f7f\u7528 as number \u4ecd\u7136\u662f\u5b57\u7b26\u4e32\uff1f\u63d2\u56fe\" alt=\"TypeScript \u7c7b\u578b\u8f6c\u6362\u7684\u56f0\u60d1\uff1a\u4e3a\u4ec0\u4e48\u4f7f\u7528 as number \u4ecd\u7136\u662f\u5b57\u7b26\u4e32\uff1f\u63d2\u56fe\" \/><\/p>\n<p><strong> \u7c7b\u578b\u8f6c\u6362\u4e2d\u7684\u56f0\u60d1\uff1a\u4e3a\u4f55 as number \u4ecd\u7136\u662f\u5b57\u7b26\u4e32\uff1f<\/strong><\/p>\n<p>\u5728 TypeScript \u4e2d\uff0c\u4f7f\u7528 as \u8fdb\u884c\u7c7b\u578b\u8f6c\u6362\u53ef\u4ee5\u6682\u65f6\u6b3a\u9a97\u7f16\u8bd1\u5668\uff0c\u4f7f\u5176\u8ba4\u4e3a\u53d8\u91cf\u5177\u6709\u4e0d\u540c\u7684\u7c7b\u578b\u3002\u7136\u800c\uff0c\u8fd9\u79cd\u8f6c\u6362\u4e0d\u4f1a\u5728\u8fd0\u884c\u65f6\u5b9e\u9645\u53d1\u751f\u3002<\/p>\n<pre>const props = defineProps&lt;{group: number }&gt;()\n\ngetDictGroup(props.group)\n\nexport const getDictGroup = async (sid: number) =&gt; {\n  const dict = await getDict()\n  console.info(typeof sid) \/\/ number\n  sid = sid as number\n  console.info(typeof (sid)) \/\/ string\n  console.info(typeof (sid as number)) \/\/ string\n}<\/pre>\n<p> \u767b\u5f55\u540e\u590d\u5236 <\/p>\n<p>\u5728\u6b64\u793a\u4f8b\u4e2d\uff0c\u6211\u4eec\u58f0\u660e sid \u4e3a\u6570\u5b57\u7c7b\u578b\uff0c\u4f46\u5373\u4f7f\u4f7f\u7528\u4e86 as number \u8f6c\u6362\uff0c\u5728\u8fd0\u884c\u65f6\u5b83\u4ecd\u7136\u662f\u4e00\u4e2a\u5b57\u7b26\u4e32\u3002\u8fd9\u662f\u56e0\u4e3a as \u8f6c\u6362\u4ec5\u5728\u7f16\u8bd1\u65f6\u6709\u6548\u3002<\/p>\n<p>\u771f\u6b63\u7684\u7c7b\u578b\u8f6c\u6362\u5e94\u4f7f\u7528\u4ee5\u4e0b\u8bed\u6cd5\u8fdb\u884c\uff1a<\/p>\n<pre>let n = 12345\nn = String(n)\nconsole.log(n) \/\/ \"12345\"<\/pre>\n<p> \u767b\u5f55\u540e\u590d\u5236 <\/p>\n<p>\u5728\u8fd9\u79cd\u60c5\u51b5\u4e0b\uff0cString(n) \u4f1a\u5c06\u6570\u5b57 n \u8f6c\u6362\u4e3a\u5b57\u7b26\u4e32\u3002\u6700\u7ec8\u5c06\u6253\u5370 &#8220;12345&#8221;\uff0c\u800c\u4e0d\u662f\u6570\u5b57\u3002<\/p>\n<p>\u4ee5\u4e0a\u5c31\u662fTypeScript \u7c7b\u578b\u8f6c\u6362\u7684\u56f0\u60d1\uff1a\u4f7f\u7528 as number \u4ecd\u7136\u662f\u5b57\u7b26\u4e32\uff1f\u7684\u8be6\u7ec6\u5185\u5bb9\uff0c\u66f4\u591a\u8bf7\u5173\u6ce8\u7c73\u4e91\u5176\u5b83\u76f8\u5173\u6587\u7ae0\uff01<\/p>\n","protected":false},"excerpt":{"rendered":"<p>\u7c7b\u578b\u8f6c\u6362\u4e2d\u7684\u56f0\u60d1\uff1a\u4e3a\u4f55 as number \u4ecd\u7136\u662f\u5b57\u7b26\u4e32\uff1f \u5728 TypeScript \u4e2d\uff0c\u4f7f\u7528 as \u8fdb\u884c\u7c7b\u578b\u8f6c\u6362\u53ef\u4ee5\u6682\u65f6\u6b3a\u9a97\u7f16\u8bd1\u5668\uff0c\u4f7f\u5176\u8ba4\u4e3a\u53d8\u91cf\u5177\u6709\u4e0d\u540c\u7684\u7c7b\u578b\u3002\u7136\u800c\uff0c\u8fd9\u79cd\u8f6c\u6362\u4e0d\u4f1a\u5728\u8fd0\u884c\u65f6\u5b9e\u9645\u53d1\u751f\u3002 const props = defineProps&lt;{group: number }&gt;() getDictGroup(props.group) export const getDictGroup = async (sid: number) =&gt; { const dict = await getDict() console.info(typeof sid) \/\/ number sid = sid as number console.info(typeof (sid)) \/\/ string console.info(typeof (sid as number)) \/\/ string } \u767b\u5f55\u540e\u590d\u5236 \u5728\u6b64\u793a\u4f8b\u4e2d\uff0c\u6211\u4eec\u58f0\u660e sid \u4e3a\u6570\u5b57\u7c7b\u578b\uff0c\u4f46\u5373\u4f7f\u4f7f\u7528\u4e86 as [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[16],"tags":[],"class_list":["post-28359","post","type-post","status-publish","format-standard","hentry","category-16"],"_links":{"self":[{"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/posts\/28359","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/comments?post=28359"}],"version-history":[{"count":0,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/posts\/28359\/revisions"}],"wp:attachment":[{"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/media?parent=28359"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/categories?post=28359"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/tags?post=28359"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}