{"id":52092,"date":"2024-12-03T10:33:30","date_gmt":"2024-12-03T02:33:30","guid":{"rendered":"https:\/\/fwq.ai\/blog\/52092\/"},"modified":"2024-12-03T10:33:30","modified_gmt":"2024-12-03T02:33:30","slug":"typescript-%e4%b8%ad-as-number-%e7%9c%9f%e7%9a%84%e4%bc%9a%e8%bd%ac%e6%8d%a2%e7%b1%bb%e5%9e%8b%e5%90%97%ef%bc%9f-2","status":"publish","type":"post","link":"https:\/\/fwq.ai\/blog\/52092\/","title":{"rendered":"TypeScript \u4e2d as number \u771f\u7684\u4f1a\u8f6c\u6362\u7c7b\u578b\u5417\uff1f"},"content":{"rendered":"<p><b><\/b>     <\/p>\n<h1>TypeScript \u4e2d as number \u771f\u7684\u4f1a\u8f6c\u6362\u7c7b\u578b\u5417\uff1f <\/h1>\n<p>\u77e5\u8bc6\u70b9\u638c\u63e1\u4e86\uff0c\u8fd8\u9700\u8981\u4e0d\u65ad\u7ec3\u4e60\u624d\u80fd\u719f\u7ec3\u8fd0\u7528\u3002\u4e0b\u9762\u7c73\u4e91\u7ed9\u5927\u5bb6\u5e26\u6765\u4e00\u4e2a\u6587\u7ae0\u5f00\u53d1\u5b9e\u6218\uff0c\u624b\u628a\u624b\u6559\u5927\u5bb6\u5b66\u4e60\u300aTypeScript \u4e2d as number \u771f\u7684\u4f1a\u8f6c\u6362\u7c7b\u578b\u5417\uff1f \u300b\uff0c\u5728\u5b9e\u73b0\u529f\u80fd\u7684\u8fc7\u7a0b\u4e2d\u4e5f\u5e26\u5927\u5bb6\u91cd\u65b0\u6e29\u4e60\u76f8\u5173\u77e5\u8bc6\u70b9\uff0c\u6e29\u6545\u800c\u77e5\u65b0\uff0c\u56de\u5934\u770b\u770b\u8bf4\u4e0d\u5b9a\u53c8\u6709\u4e0d\u4e00\u6837\u7684\u611f\u609f\uff01<\/p>\n<p><img decoding=\"async\" src=\"https:\/\/www.17golang.com\/uploads\/20241119\/1731977691673be1dbb3e42.jpg\" class=\"aligncenter\" title=\"TypeScript \u4e2d as number \u771f\u7684\u4f1a\u8f6c\u6362\u7c7b\u578b\u5417\uff1f\u63d2\u56fe\" alt=\"TypeScript \u4e2d as number \u771f\u7684\u4f1a\u8f6c\u6362\u7c7b\u578b\u5417\uff1f\u63d2\u56fe\" \/><\/p>\n<p><strong>TypeScript \u4e2d as number \u7c7b\u578b\u8f6c\u6362\u7684\u672c\u8d28<\/strong><\/p>\n<p>\u5728 TypeScript \u4e2d\uff0cas number \u7c7b\u578b\u8f6c\u6362\u5e38\u7528\u4e8e\u5f3a\u8f6c\u4e00\u4e2a\u503c\u7c7b\u578b\u4e3a\u6570\u5b57\u3002\u4e0d\u8fc7\uff0c\u4e0e\u9884\u671f\u4e0d\u540c\u7684\u662f\uff0c\u8be5\u7c7b\u578b\u8f6c\u6362\u4e0d\u4f1a\u5728\u8fd0\u884c\u65f6\u5b9e\u9645\u8f6c\u6362\u503c\u3002<\/p>\n<p>\u8003\u8651\u4ee5\u4e0b\u793a\u4f8b\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); \/\/ \"string\"\n  sid = sid as number;\n  console.info(typeof sid); \/\/ \"number\"\n  console.info(typeof (sid as number)); \/\/ \"number\"\n};<\/pre>\n<p>\u5982\u4f60\u6240\u89c1\uff0c\u5373\u4f7f\u5728\u591a\u6b21\u58f0\u660e sid \u4e3a\u6570\u5b57\u7c7b\u578b\uff0c\u6253\u5370\u51fa\u6765\u7684\u7c7b\u578b\u4ecd\u7136\u662f\u5b57\u7b26\u4e32\u3002\u8fd9\u662f\u56e0\u4e3a as number \u6b3a\u9a97\u4e86\u7f16\u8bd1\u5668\uff0c\u800c\u4e0d\u4f1a\u5728\u8fd0\u884c\u65f6\u6267\u884c\u771f\u6b63\u7684\u7c7b\u578b\u8f6c\u6362\u3002<\/p>\n<p>\u6b63\u786e\u7684 TypeScript \u7c7b\u578b\u8f6c\u6362\u5e94\u4f7f\u7528 Number() \u6216 parseInt() \u51fd\u6570\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); \/\/ \"string\"\n  \/\/ \u4f7f\u7528 Number \u8f6c\u6362\n  sid = Number(sid);\n  \/\/ \u4f7f\u7528 parseInt \u8f6c\u6362\n  sid = parseInt(sid);\n  console.info(typeof sid); \/\/ \"number\"\n};<\/pre>\n<p>\u6587\u4e2d\u5173\u4e8e\u7684\u77e5\u8bc6\u4ecb\u7ecd\uff0c\u5e0c\u671b\u5bf9\u4f60\u7684\u5b66\u4e60\u6709\u6240\u5e2e\u52a9\uff01\u82e5\u662f\u53d7\u76ca\u532a\u6d45\uff0c\u90a3\u5c31\u52a8\u52a8\u9f20\u6807\u6536\u85cf\u8fd9\u7bc7\u300aTypeScript \u4e2d as number \u771f\u7684\u4f1a\u8f6c\u6362\u7c7b\u578b\u5417\uff1f \u300b\u6587\u7ae0\u5427\uff0c\u4e5f\u53ef\u5173\u6ce8\u7c73\u4e91\u516c\u4f17\u53f7\u4e86\u89e3\u76f8\u5173\u6280\u672f\u6587\u7ae0\u3002<\/p>\n<dl>\n<dt><\/dt>\n<dd>\n   CSS \u4e2d height\u3001max-height\u3001min-height \u540c\u65f6\u4f7f\u7528\u65f6\uff0c\u8c01\u7684\u4f18\u5148\u7ea7\u6700\u9ad8\uff1f\n <\/dd>\n<\/dl>\n","protected":false},"excerpt":{"rendered":"<p>TypeScript \u4e2d as number \u771f\u7684\u4f1a\u8f6c\u6362\u7c7b\u578b\u5417\uff1f \u77e5\u8bc6\u70b9\u638c\u63e1\u4e86\uff0c\u8fd8\u9700\u8981\u4e0d\u65ad\u7ec3\u4e60\u624d\u80fd\u719f\u7ec3\u8fd0\u7528\u3002\u4e0b\u9762\u7c73\u4e91\u7ed9\u5927\u5bb6\u5e26\u6765\u4e00\u4e2a\u6587\u7ae0\u5f00\u53d1\u5b9e\u6218\uff0c\u624b\u628a\u624b\u6559\u5927\u5bb6\u5b66\u4e60\u300aTypeScript \u4e2d as number \u771f\u7684\u4f1a\u8f6c\u6362\u7c7b\u578b\u5417\uff1f \u300b\uff0c\u5728\u5b9e\u73b0\u529f\u80fd\u7684\u8fc7\u7a0b\u4e2d\u4e5f\u5e26\u5927\u5bb6\u91cd\u65b0\u6e29\u4e60\u76f8\u5173\u77e5\u8bc6\u70b9\uff0c\u6e29\u6545\u800c\u77e5\u65b0\uff0c\u56de\u5934\u770b\u770b\u8bf4\u4e0d\u5b9a\u53c8\u6709\u4e0d\u4e00\u6837\u7684\u611f\u609f\uff01 TypeScript \u4e2d as number \u7c7b\u578b\u8f6c\u6362\u7684\u672c\u8d28 \u5728 TypeScript \u4e2d\uff0cas number \u7c7b\u578b\u8f6c\u6362\u5e38\u7528\u4e8e\u5f3a\u8f6c\u4e00\u4e2a\u503c\u7c7b\u578b\u4e3a\u6570\u5b57\u3002\u4e0d\u8fc7\uff0c\u4e0e\u9884\u671f\u4e0d\u540c\u7684\u662f\uff0c\u8be5\u7c7b\u578b\u8f6c\u6362\u4e0d\u4f1a\u5728\u8fd0\u884c\u65f6\u5b9e\u9645\u8f6c\u6362\u503c\u3002 \u8003\u8651\u4ee5\u4e0b\u793a\u4f8b\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); \/\/ &#8220;string&#8221; sid = sid as number; console.info(typeof sid); [&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-52092","post","type-post","status-publish","format-standard","hentry","category-16"],"_links":{"self":[{"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/posts\/52092","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=52092"}],"version-history":[{"count":0,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/posts\/52092\/revisions"}],"wp:attachment":[{"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/media?parent=52092"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/categories?post=52092"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/tags?post=52092"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}