{"id":4950,"date":"2023-01-05T11:25:40","date_gmt":"2023-01-05T03:25:40","guid":{"rendered":"https:\/\/badgameshow.com\/steven\/?p=4950"},"modified":"2023-01-05T11:25:40","modified_gmt":"2023-01-05T03:25:40","slug":"%e6%b7%b1%e5%85%a5%e6%8e%a2%e7%b4%a2typescript%e4%b8%ad%e7%9a%84%e7%b1%bb%e5%9e%8b%e6%96%ad%e8%a8%80%e3%80%81%e7%b1%bb%e5%9e%8b%e5%ae%88%e5%8d%ab%e8%88%87%e7%b1%bb%e5%9e%8b%e5%88%ab%e5%90%8d","status":"publish","type":"post","link":"https:\/\/badgameshow.com\/steven\/typescript\/%e6%b7%b1%e5%85%a5%e6%8e%a2%e7%b4%a2typescript%e4%b8%ad%e7%9a%84%e7%b1%bb%e5%9e%8b%e6%96%ad%e8%a8%80%e3%80%81%e7%b1%bb%e5%9e%8b%e5%ae%88%e5%8d%ab%e8%88%87%e7%b1%bb%e5%9e%8b%e5%88%ab%e5%90%8d\/","title":{"rendered":"\u6df1\u5165\u63a2\u7d22TypeScript\u4e2d\u7684\u7c7b\u578b\u65ad\u8a00\u3001\u7c7b\u578b\u5b88\u536b\u8207\u7c7b\u578b\u522b\u540d"},"content":{"rendered":"<p><meta name=\"keywords\" content=\"TypeScript, \u7c7b\u578b\u65ad\u8a00, \u7c7b\u578b\u5b88\u536b, \u7c7b\u578b\u522b\u540d, \u6bd4\u8f83\"><\/p>\n<p>TypeScript \u662f\u4e00\u7a2e\u7531 Microsoft \u958b\u767c\u7684 JavaScript \u7684\u8d85\u96c6\uff0c\u5b83\u64c1\u6709\u5f37\u5927\u7684\u985e\u578b\u7cfb\u7d71\uff0c\u53ef\u4ee5\u63d0\u4f9b\u66f4\u591a\u7684\u5b89\u5168\u6027\u548c\u53ef\u9760\u6027\u3002\u5728 TypeScript \u4e2d\uff0c\u6709\u4e09\u7a2e\u985e\u578b\u7684\u5de5\u5177\u53ef\u4ee5\u5e6b\u52a9\u958b\u767c\u8005\u66f4\u597d\u5730\u7ba1\u7406\u548c\u63a7\u5236\u985e\u578b\uff0c\u5b83\u5011\u5206\u5225\u662f\uff1a\u7c7b\u578b\u65ad\u8a00\u3001\u7c7b\u578b\u5b88\u536b\u548c\u7c7b\u578b\u522b\u540d\u3002\u672c\u6587\u5c07\u6bd4\u8f03\u9019\u4e09\u7a2e\u5de5\u5177\uff0c\u4e26\u8a73\u7d30\u89e3\u91cb\u5b83\u5011\u7684\u7528\u9014\u3002<\/p>\n<h2>TypeScript \u7c7b\u578b\u65ad\u8a00<\/h2>\n<p>TypeScript \u7c7b\u578b\u65ad\u8a00\u662f\u4e00\u79cd\u5f37\u5236\u5c07\u4e00\u500b\u8b8a\u91cf\u7684\u985e\u578b\u8f49\u63db\u70ba\u53e6\u4e00\u500b\u985e\u578b\u7684\u65b9\u6cd5\u3002\u5b83\u53ef\u4ee5\u8b93\u958b\u767c\u8005\u5728\u4e0d\u6539\u8b8a\u8b8a\u91cf\u7684\u503c\u7684\u60c5\u6cc1\u4e0b\uff0c\u5c07\u8b8a\u91cf\u7684\u985e\u578b\u8f49\u63db\u70ba\u66f4\u52a0\u5177\u9ad4\u7684\u985e\u578b\u3002\u4f8b\u5982\uff0c\u5047\u8a2d\u6211\u5011\u6709\u4e00\u500b\u8b8a\u91cf x\uff0c\u5b83\u7684\u985e\u578b\u662f any\uff0c\u6211\u5011\u53ef\u4ee5\u4f7f\u7528\u7c7b\u578b\u65ad\u8a00\u5c07\u5b83\u7684\u985e\u578b\u8f49\u63db\u70ba string\uff1a<\/p>\n<pre class=\"brush: javascript\">\nlet x: any = \"Hello World\";\nlet y = x as string;\n<\/pre>\n<p>\u901a\u904e\u4f7f\u7528\u7c7b\u578b\u65ad\u8a00\uff0c\u6211\u5011\u53ef\u4ee5\u5c07 x \u7684\u985e\u578b\u5f9e any \u8f49\u63db\u70ba string\uff0c\u4e26\u5c07\u5176\u503c\u8ce6\u7d66 y\u3002<\/p>\n<h2>TypeScript \u7c7b\u578b\u5b88\u536b<\/h2>\n<p>TypeScript \u7c7b\u578b\u5b88\u536b\u662f\u4e00\u7a2e\u6aa2\u67e5\u8b8a\u91cf\u985e\u578b\u7684\u65b9\u6cd5\uff0c\u5b83\u53ef\u4ee5\u8b93\u958b\u767c\u8005\u5728\u7a0b\u5e8f\u57f7\u884c\u6642\u6aa2\u67e5\u8b8a\u91cf\u7684\u985e\u578b\uff0c\u4e26\u57fa\u65bc\u8b8a\u91cf\u7684\u985e\u578b\u505a\u51fa\u4e0d\u540c\u7684\u64cd\u4f5c\u3002\u4f8b\u5982\uff0c\u5047\u8a2d\u6211\u5011\u6709\u4e00\u500b\u8b8a\u91cf x\uff0c\u5b83\u7684\u985e\u578b\u662f any\uff0c\u6211\u5011\u53ef\u4ee5\u4f7f\u7528\u7c7b\u578b\u5b88\u536b\u6aa2\u67e5 x \u7684\u985e\u578b\uff1a<\/p>\n<pre class=\"brush: javascript\">\nlet x: any = \"Hello World\";\nif (typeof x === \"string\") {\n  console.log(\"x is a string\");\n}\n<\/pre>\n<p>\u901a\u904e\u4f7f\u7528\u7c7b\u578b\u5b88\u536b\uff0c\u6211\u5011\u53ef\u4ee5\u6aa2\u67e5 x \u7684\u985e\u578b\u662f\u5426\u70ba string\uff0c\u4e26\u57fa\u65bc\u6aa2\u67e5\u7d50\u679c\u505a\u51fa\u4e0d\u540c\u7684\u64cd\u4f5c\u3002<\/p>\n<h2>TypeScript \u7c7b\u578b\u522b\u540d<\/h2>\n<p>TypeScript \u7c7b\u578b\u522b\u540d\u662f\u4e00\u7a2e\u70ba\u985e\u578b\u5b9a\u7fa9\u5225\u540d\u7684\u65b9\u6cd5\uff0c\u5b83\u53ef\u4ee5\u8b93\u958b\u767c\u8005\u5c07\u4e00\u500b\u8907\u96dc\u7684\u985e\u578b\u5b9a\u7fa9\u7c21\u5316\u70ba\u4e00\u500b\u7c21\u55ae\u7684\u5225\u540d\u3002\u4f8b\u5982\uff0c\u5047\u8a2d\u6211\u5011\u6709\u4e00\u500b\u8907\u96dc\u7684\u985e\u578b\u5b9a\u7fa9\uff1a<\/p>\n<pre class=\"brush: javascript\">\ntype ComplexType = {\n  name: string;\n  age: number;\n  address: string;\n};\n<\/pre>\n<p>\u6211\u5011\u53ef\u4ee5\u4f7f\u7528\u7c7b\u578b\u522b\u540d\u5c07\u5b83\u7c21\u5316\u70ba\u4e00\u500b\u7c21\u55ae\u7684\u5225\u540d\uff1a<\/p>\n<pre class=\"brush: javascript\">\ntype Person = ComplexType;\n<\/pre>\n<p>\u901a\u904e\u4f7f\u7528\u7c7b\u578b\u522b\u540d\uff0c\u6211\u5011\u53ef\u4ee5\u5c07\u8907\u96dc\u7684\u985e\u578b\u5b9a\u7fa9\u7c21\u5316\u70ba\u4e00\u500b\u7c21\u55ae\u7684\u5225\u540d\uff0c\u4e26\u5c07\u5176\u7528\u65bc\u5176\u4ed6\u5730\u65b9\u3002<\/p>\n<p><!--more--><\/p>\n<p>\u7e3d\u7d50\u4f86\u8aaa\uff0cTypeScript \u7c7b\u578b\u65ad\u8a00\u3001\u7c7b\u578b\u5b88\u536b\u548c\u7c7b\u578b\u522b\u540d\u90fd\u662f TypeScript \u4e2d\u5f37\u5927\u7684\u985e\u578b\u7cfb\u7d71\u7684\u91cd\u8981\u7d44\u6210\u90e8\u5206\uff0c\u5b83\u5011\u53ef\u4ee5\u5e6b\u52a9\u958b\u767c\u8005\u66f4\u597d\u5730\u7ba1\u7406\u548c\u63a7\u5236\u985e\u578b\u3002\u7c7b\u578b\u65ad\u8a00\u53ef\u4ee5\u8b93\u958b\u767c\u8005\u5c07\u8b8a\u91cf\u7684\u985e\u578b\u8f49\u63db\u70ba\u66f4\u52a0\u5177\u9ad4\u7684\u985e\u578b\uff0c\u7c7b\u578b\u5b88\u536b\u53ef\u4ee5\u8b93\u958b\u767c\u8005\u5728\u7a0b\u5e8f\u57f7\u884c\u6642\u6aa2\u67e5\u8b8a\u91cf\u7684\u985e\u578b\uff0c\u800c\u7c7b\u578b\u522b\u540d\u5247\u53ef\u4ee5\u8b93\u958b\u767c\u8005\u5c07\u8907\u96dc\u7684\u985e\u578b\u5b9a\u7fa9\u7c21\u5316\u70ba\u4e00\u500b\u7c21\u55ae\u7684\u5225\u540d\u3002<\/p>\n","protected":false},"excerpt":{"rendered":"<p>\u6587\u7ae0\u6458\u8981\uff1a\u672c\u6587\u5c07\u6df1\u5165\u63a2\u8a0eTypeScript\u4e2d\u7684\u7c7b\u578b\u65ad\u8a00\u3001\u7c7b\u578b\u5b88\u536b\u8207\u7c7b\u578b\u522b\u540d\uff0c\u8b93\u8b80\u8005\u66f4\u52a0\u4e86\u89e3\u5b83\u5011\u7684\u529f\u80fd\u8207\u4f7f\u7528\u65b9\u5f0f\uff0c\u4e26\u638c\u63e1\u5982\u4f55\u6709\u6548\u5730\u5229\u7528\u5b83\u5011\u4f86\u63d0\u5347\u7a0b\u5f0f\u78bc\u7684\u54c1\u8cea\u3002<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"_jetpack_memberships_contains_paid_content":false,"footnotes":"","jetpack_publicize_message":"","jetpack_publicize_feature_enabled":true,"jetpack_social_post_already_shared":true,"jetpack_social_options":{"image_generator_settings":{"template":"highway","default_image_id":0,"font":"","enabled":false},"version":2}},"categories":[187],"tags":[186],"class_list":["post-4950","post","type-post","status-publish","format-standard","hentry","category-typescript","tag-typescript"],"jetpack_publicize_connections":[],"jetpack_featured_media_url":"","jetpack-related-posts":[],"jetpack_shortlink":"https:\/\/wp.me\/pcFK27-1hQ","jetpack_sharing_enabled":true,"_links":{"self":[{"href":"https:\/\/badgameshow.com\/steven\/wp-json\/wp\/v2\/posts\/4950","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/badgameshow.com\/steven\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/badgameshow.com\/steven\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/badgameshow.com\/steven\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/badgameshow.com\/steven\/wp-json\/wp\/v2\/comments?post=4950"}],"version-history":[{"count":1,"href":"https:\/\/badgameshow.com\/steven\/wp-json\/wp\/v2\/posts\/4950\/revisions"}],"predecessor-version":[{"id":4951,"href":"https:\/\/badgameshow.com\/steven\/wp-json\/wp\/v2\/posts\/4950\/revisions\/4951"}],"wp:attachment":[{"href":"https:\/\/badgameshow.com\/steven\/wp-json\/wp\/v2\/media?parent=4950"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/badgameshow.com\/steven\/wp-json\/wp\/v2\/categories?post=4950"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/badgameshow.com\/steven\/wp-json\/wp\/v2\/tags?post=4950"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}