{"id":52015,"date":"2024-12-03T17:21:23","date_gmt":"2024-12-03T09:21:23","guid":{"rendered":"https:\/\/fwq.ai\/blog\/52015\/"},"modified":"2024-12-03T17:21:23","modified_gmt":"2024-12-03T09:21:23","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-2","status":"publish","type":"post","link":"https:\/\/fwq.ai\/blog\/52015\/","title":{"rendered":"TypeScript \u4e2d\u7684 as \u7c7b\u578b\u8f6c\u6362\u4e3a\u4f55\u5931\u6548\uff1f"},"content":{"rendered":"<p><b><\/b>     <\/p>\n<h1>TypeScript \u4e2d\u7684 as \u7c7b\u578b\u8f6c\u6362\u4e3a\u4f55\u5931\u6548\uff1f <\/h1>\n<p>\u5927\u5bb6\u597d\uff0c\u4eca\u5929\u672c\u4eba\u7ed9\u5927\u5bb6\u5e26\u6765\u6587\u7ae0<span style=\"color: #FF6600;, Helvetica, Arial, sans-serif;font-size: 14px;background-color: #FFFFFF\">\u300aTypeScript \u4e2d\u7684 as \u7c7b\u578b\u8f6c\u6362\u4e3a\u4f55\u5931\u6548\uff1f \u300b<\/span>\uff0c\u6587\u4e2d\u5185\u5bb9\u4e3b\u8981\u6d89\u53ca\u5230<span style=\"color: #FF6600;, Helvetica, Arial, sans-serif;font-size: 14px;background-color: #FFFFFF\"><span style=\"color: #FF6600;, Helvetica, Arial, sans-serif;font-size: 14px;background-color: #FFFFFF\"><\/span><\/span>\uff0c\u5982\u679c\u4f60\u5bf9<span style=\"color: #FF6600;, Helvetica, Arial, sans-serif;font-size: 14px;background-color: #FFFFFF\">\u6587\u7ae0<\/span>\u65b9\u9762\u7684\u77e5\u8bc6\u70b9\u611f\u5174\u8da3\uff0c\u90a3\u5c31\u8bf7\u5404\u4f4d\u670b\u53cb\u7ee7\u7eed\u770b\u4e0b\u53bb\u5427~\u5e0c\u671b\u80fd\u771f\u6b63\u5e2e\u5230\u4f60\u4eec\uff0c\u8c22\u8c22\uff01<\/p>\n<p><img decoding=\"async\" src=\"https:\/\/www.17golang.com\/uploads\/20241118\/1731919536673afeb065333.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>\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>\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>\u4eca\u5929\u5e26\u5927\u5bb6\u4e86\u89e3\u4e86\u7684\u76f8\u5173\u77e5\u8bc6\uff0c\u5e0c\u671b\u5bf9\u4f60\u6709\u6240\u5e2e\u52a9\uff1b\u5173\u4e8e\u6587\u7ae0\u7684\u6280\u672f\u77e5\u8bc6\u6211\u4eec\u4f1a\u4e00\u70b9\u70b9\u6df1\u5165\u4ecb\u7ecd\uff0c\u6b22\u8fce\u5927\u5bb6\u5173\u6ce8\u7c73\u4e91\u516c\u4f17\u53f7\uff0c\u4e00\u8d77\u5b66\u4e60\u7f16\u7a0b~<\/p>\n<dl>\n<dt><\/dt>\n<dd>\n   VSCode\u5185\u7f6e\u4e86\u54ea\u4e9b\u8bed\u8a00\u63d2\u4ef6\uff1f\u5982\u4f55\u67e5\u770b\u5b83\u4eec\uff1f\n <\/dd>\n<\/dl>\n","protected":false},"excerpt":{"rendered":"<p>TypeScript \u4e2d\u7684 as \u7c7b\u578b\u8f6c\u6362\u4e3a\u4f55\u5931\u6548\uff1f \u5927\u5bb6\u597d\uff0c\u4eca\u5929\u672c\u4eba\u7ed9\u5927\u5bb6\u5e26\u6765\u6587\u7ae0\u300aTypeScript \u4e2d\u7684 as \u7c7b\u578b\u8f6c\u6362\u4e3a\u4f55\u5931\u6548\uff1f \u300b\uff0c\u6587\u4e2d\u5185\u5bb9\u4e3b\u8981\u6d89\u53ca\u5230\uff0c\u5982\u679c\u4f60\u5bf9\u6587\u7ae0\u65b9\u9762\u7684\u77e5\u8bc6\u70b9\u611f\u5174\u8da3\uff0c\u90a3\u5c31\u8bf7\u5404\u4f4d\u670b\u53cb\u7ee7\u7eed\u770b\u4e0b\u53bb\u5427~\u5e0c\u671b\u80fd\u771f\u6b63\u5e2e\u5230\u4f60\u4eec\uff0c\u8c22\u8c22\uff01 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)) } \u5c3d\u7ba1\u4ee3\u7801\u4e2d\u58f0\u660e\u4e86 [&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-52015","post","type-post","status-publish","format-standard","hentry","category-16"],"_links":{"self":[{"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/posts\/52015","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=52015"}],"version-history":[{"count":0,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/posts\/52015\/revisions"}],"wp:attachment":[{"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/media?parent=52015"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/categories?post=52015"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/tags?post=52015"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}