{"id":28340,"date":"2024-11-24T13:36:13","date_gmt":"2024-11-24T05:36:13","guid":{"rendered":"https:\/\/fwq.ai\/blog\/28340\/"},"modified":"2024-11-24T13:36:13","modified_gmt":"2024-11-24T05:36:13","slug":"typescript-%e4%b8%ad%e7%9a%84-as-%e7%b1%bb%e5%9e%8b%e8%bd%ac%e6%8d%a2%e4%b8%ba%e4%bd%95%e5%a4%b1%e6%95%88%ef%bc%9f","status":"publish","type":"post","link":"https:\/\/fwq.ai\/blog\/28340\/","title":{"rendered":"TypeScript \u4e2d\u7684 as \u7c7b\u578b\u8f6c\u6362\u4e3a\u4f55\u5931\u6548\uff1f"},"content":{"rendered":"<p><img decoding=\"async\" src=\"https:\/\/img.php.cn\/upload\/article\/001\/246\/273\/173155861427868.jpg\" class=\"aligncenter\" title=\"TypeScript \u4e2d\u7684 as \u7c7b\u578b\u8f6c\u6362\u4e3a\u4f55\u5931\u6548\uff1f\u63d2\u56fe\" alt=\"TypeScript \u4e2d\u7684 as \u7c7b\u578b\u8f6c\u6362\u4e3a\u4f55\u5931\u6548\uff1f\u63d2\u56fe\" \/><\/p>\n<p><strong>ts \u7c7b\u578b\u8f6c\u6362\u4e3a\u4f55\u5931\u6548\uff1f<\/strong><\/p>\n<p>\u5728 TypeScript \u4e2d\uff0cas \u8fd0\u7b97\u7b26\u7528\u4e8e\u7c7b\u578b\u8f6c\u6362\uff0c\u4f46\u5728\u67d0\u4e9b\u60c5\u51b5\u4e0b\uff0cas number \u8f6c\u6362\u53ef\u80fd\u65e0\u6cd5\u5c06\u5b57\u7b26\u4e32\u8f6c\u6362\u4e3a\u6570\u5b57\u3002<\/p>\n<p>\u8003\u8651\u4ee5\u4e0b\u4ee3\u7801\uff1a<\/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)\n  sid = sid as number\n  console.info(typeof (sid))\n  console.info(typeof (sid as number))\n}<\/pre>\n<p>  \u767b\u5f55\u540e\u590d\u5236   <\/p>\n<p>\u5c3d\u7ba1\u4ee3\u7801\u4e2d\u58f0\u660e\u4e86 sid \u662f number \u7c7b\u578b\uff0c\u4f46\u8f93\u51fa\u7ed3\u679c\u5374\u662f\u5b57\u7b26\u4e32\u3002\u8fd9\u662f\u56e0\u4e3a as \u8fd0\u7b97\u7b26\u53ea\u662f\u6b3a\u9a97\u7f16\u8bd1\u5668\uff0c\u800c\u4e0d\u4f1a\u5728\u8fd0\u884c\u65f6\u5b9e\u9645\u8fdb\u884c\u7c7b\u578b\u8f6c\u6362\u3002<\/p>\n<p>\u6b63\u786e\u7684\u7c7b\u578b\u8f6c\u6362\u65b9\u5f0f\u5e94\u8be5\u5982\u4e0b\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\u4e2a\u793a\u4f8b\u4e2d\uff0cString() \u51fd\u6570\u5c06\u6570\u5b57 12345 \u8f6c\u6362\u4e3a\u5b57\u7b26\u4e32 &#8220;12345&#8221;\u3002<\/p>\n<p>\u4ee5\u4e0a\u5c31\u662fTypeScript \u4e2d\u7684 as \u7c7b\u578b\u8f6c\u6362\u4e3a\u4f55\u5931\u6548\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>ts \u7c7b\u578b\u8f6c\u6362\u4e3a\u4f55\u5931\u6548\uff1f \u5728 TypeScript \u4e2d\uff0cas \u8fd0\u7b97\u7b26\u7528\u4e8e\u7c7b\u578b\u8f6c\u6362\uff0c\u4f46\u5728\u67d0\u4e9b\u60c5\u51b5\u4e0b\uff0cas number \u8f6c\u6362\u53ef\u80fd\u65e0\u6cd5\u5c06\u5b57\u7b26\u4e32\u8f6c\u6362\u4e3a\u6570\u5b57\u3002 \u8003\u8651\u4ee5\u4e0b\u4ee3\u7801\uff1a 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) sid = sid as number console.info(typeof (sid)) console.info(typeof (sid as number)) } \u767b\u5f55\u540e\u590d\u5236 \u5c3d\u7ba1\u4ee3\u7801\u4e2d\u58f0\u660e\u4e86 sid \u662f number \u7c7b\u578b\uff0c\u4f46\u8f93\u51fa\u7ed3\u679c\u5374\u662f\u5b57\u7b26\u4e32\u3002\u8fd9\u662f\u56e0\u4e3a as \u8fd0\u7b97\u7b26\u53ea\u662f\u6b3a\u9a97\u7f16\u8bd1\u5668\uff0c\u800c\u4e0d\u4f1a\u5728\u8fd0\u884c\u65f6\u5b9e\u9645\u8fdb\u884c\u7c7b\u578b\u8f6c\u6362\u3002 \u6b63\u786e\u7684\u7c7b\u578b\u8f6c\u6362\u65b9\u5f0f\u5e94\u8be5\u5982\u4e0b\uff1a let [&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-28340","post","type-post","status-publish","format-standard","hentry","category-16"],"_links":{"self":[{"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/posts\/28340","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=28340"}],"version-history":[{"count":0,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/posts\/28340\/revisions"}],"wp:attachment":[{"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/media?parent=28340"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/categories?post=28340"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/tags?post=28340"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}