{"id":4898,"date":"2023-01-05T11:15:20","date_gmt":"2023-01-05T03:15:20","guid":{"rendered":"https:\/\/badgameshow.com\/steven\/?p=4898"},"modified":"2023-01-05T11:15:20","modified_gmt":"2023-01-05T03:15:20","slug":"%e6%b7%b1%e5%85%a5%e6%8e%a2%e7%b4%a2typescript%e7%b1%bb%e5%9e%8b%e6%96%ad%e8%a8%80%e4%b8%8e%e7%b1%bb%e5%9e%8b%e5%ae%88%e5%8d%ab%e7%9a%84%e6%af%94%e8%be%83","status":"publish","type":"post","link":"https:\/\/badgameshow.com\/steven\/typescript\/%e6%b7%b1%e5%85%a5%e6%8e%a2%e7%b4%a2typescript%e7%b1%bb%e5%9e%8b%e6%96%ad%e8%a8%80%e4%b8%8e%e7%b1%bb%e5%9e%8b%e5%ae%88%e5%8d%ab%e7%9a%84%e6%af%94%e8%be%83\/","title":{"rendered":"\u6df1\u5165\u63a2\u7d22TypeScript\u7c7b\u578b\u65ad\u8a00\u4e0e\u7c7b\u578b\u5b88\u536b\u7684\u6bd4\u8f83"},"content":{"rendered":"<p><meta name=\"keywords\" content=\"TypeScript, \u7c7b\u578b\u65ad\u8a00, \u7c7b\u578b\u5b88\u536b\"><\/p>\n<h1>TypeScript \u7c7b\u578b\u65ad\u8a00\u4e0e\u7c7b\u578b\u5b88\u536b\u7684\u6bd4\u8f83<\/h1>\n<p>TypeScript \u662f\u4e00\u7a2e\u5f37\u578b\u5225\u7684 JavaScript \u8a9e\u8a00\uff0c\u5b83\u63d0\u4f9b\u4e86\u5169\u7a2e\u65b9\u5f0f\u4f86\u6539\u8b8a\u985e\u578b\u6aa2\u67e5\u7684\u884c\u70ba\uff1a\u7c7b\u578b\u65ad\u8a00\u548c\u7c7b\u578b\u5b88\u536b\u3002\u672c\u6587\u5c07\u8a73\u7d30\u4ecb\u7d39\u9019\u5169\u7a2e\u65b9\u5f0f\u7684\u6bd4\u8f83\uff0c\u4ee5\u53ca\u5b83\u5011\u5728 TypeScript \u4e2d\u7684\u61c9\u7528\u3002<\/p>\n<p><!--more--><\/p>\n<h2>\u7c7b\u578b\u65ad\u8a00<\/h2>\n<p>\u7c7b\u578b\u65ad\u8a00\u662f\u4e00\u7a2e\u6280\u8853\uff0c\u53ef\u4ee5\u8b93\u958b\u767c\u8005\u5728\u4e0d\u6539\u8b8a\u985e\u578b\u6aa2\u67e5\u884c\u70ba\u7684\u60c5\u6cc1\u4e0b\uff0c\u6539\u8b8a\u985e\u578b\u6aa2\u67e5\u5668\u5c0d\u67d0\u500b\u8868\u9054\u5f0f\u7684\u63a8\u65b7\u7d50\u679c\u3002\u5b83\u53ef\u4ee5\u8b93\u958b\u767c\u8005\u5728\u4e0d\u6539\u8b8a\u985e\u578b\u6aa2\u67e5\u884c\u70ba\u7684\u60c5\u6cc1\u4e0b\uff0c\u6539\u8b8a\u985e\u578b\u6aa2\u67e5\u5668\u5c0d\u67d0\u500b\u8868\u9054\u5f0f\u7684\u63a8\u65b7\u7d50\u679c\u3002<\/p>\n<p>\u7c7b\u578b\u65ad\u8a00\u53ef\u4ee5\u7528\u65bc\u4ee5\u4e0b\u5169\u7a2e\u60c5\u6cc1\uff1a<\/p>\n<ul>\n<li>\u7576\u958b\u767c\u8005\u78ba\u5b9a\u67d0\u500b\u8868\u9054\u5f0f\u7684\u985e\u578b\u6642\uff0c\u53ef\u4ee5\u4f7f\u7528\u7c7b\u578b\u65ad\u8a00\u4f86\u6539\u8b8a\u985e\u578b\u6aa2\u67e5\u5668\u5c0d\u8a72\u8868\u9054\u5f0f\u7684\u63a8\u65b7\u7d50\u679c\u3002<\/li>\n<li>\u7576\u958b\u767c\u8005\u78ba\u5b9a\u67d0\u500b\u8868\u9054\u5f0f\u7684\u985e\u578b\u6642\uff0c\u53ef\u4ee5\u4f7f\u7528\u7c7b\u578b\u65ad\u8a00\u4f86\u6539\u8b8a\u985e\u578b\u6aa2\u67e5\u5668\u5c0d\u8a72\u8868\u9054\u5f0f\u7684\u63a8\u65b7\u7d50\u679c\u3002<\/li>\n<\/ul>\n<p>\u8209\u500b\u4f8b\u5b50\uff0c\u5047\u8a2d\u6211\u5011\u6709\u4e00\u500b\u51fd\u6578\uff0c\u5b83\u63a5\u53d7\u4e00\u500b\u53c3\u6578\uff0c\u8a72\u53c3\u6578\u7684\u985e\u578b\u662f <code>any<\/code>\uff1a<\/p>\n<pre class=\"brush: javascript\">\nfunction foo(x: any) {\n    \/\/ ...\n}\n<\/pre>\n<p>\u5047\u8a2d\u6211\u5011\u78ba\u5b9a\u8a72\u53c3\u6578\u7684\u985e\u578b\u662f <code>string<\/code>\uff0c\u90a3\u9ebc\u6211\u5011\u53ef\u4ee5\u4f7f\u7528\u7c7b\u578b\u65ad\u8a00\u4f86\u6539\u8b8a\u985e\u578b\u6aa2\u67e5\u5668\u5c0d\u8a72\u53c3\u6578\u7684\u63a8\u65b7\u7d50\u679c\uff1a<\/p>\n<pre class=\"brush: javascript\">\nfunction foo(x: any) {\n    \/\/ \u7c7b\u578b\u65ad\u8a00\n    let str = <string>x;\n    \/\/ ...\n}\n<\/pre>\n<p>\u901a\u904e\u7c7b\u578b\u65ad\u8a00\uff0c\u6211\u5011\u53ef\u4ee5\u6539\u8b8a\u985e\u578b\u6aa2\u67e5\u5668\u5c0d\u8a72\u53c3\u6578\u7684\u63a8\u65b7\u7d50\u679c\uff0c\u4f7f\u5f97\u8a72\u53c3\u6578\u7684\u985e\u578b\u88ab\u63a8\u65b7\u70ba <code>string<\/code>\u3002<\/p>\n<h2>\u7c7b\u578b\u5b88\u536b<\/h2>\n<p>\u7c7b\u578b\u5b88\u536b\u662f\u4e00\u7a2e\u6280\u8853\uff0c\u53ef\u4ee5\u8b93\u958b\u767c\u8005\u5728\u4e0d\u6539\u8b8a\u985e\u578b\u6aa2\u67e5\u884c\u70ba\u7684\u60c5\u6cc1\u4e0b\uff0c\u6539\u8b8a\u985e\u578b\u6aa2\u67e5\u5668\u5c0d\u67d0\u500b\u8868\u9054\u5f0f\u7684\u63a8\u65b7\u7d50\u679c\u3002\u5b83\u53ef\u4ee5\u8b93\u958b\u767c\u8005\u5728\u4e0d\u6539\u8b8a\u985e\u578b\u6aa2\u67e5\u884c\u70ba\u7684\u60c5\u6cc1\u4e0b\uff0c\u6539\u8b8a\u985e\u578b\u6aa2\u67e5\u5668\u5c0d\u67d0\u500b\u8868\u9054\u5f0f\u7684\u63a8\u65b7\u7d50\u679c\u3002<\/p>\n<p>\u8209\u500b\u4f8b\u5b50\uff0c\u5047\u8a2d\u6211\u5011\u6709\u4e00\u500b\u51fd\u6578\uff0c\u5b83\u63a5\u53d7\u4e00\u500b\u53c3\u6578\uff0c\u8a72\u53c3\u6578\u7684\u985e\u578b\u662f <code>any<\/code>\uff1a<\/p>\n<pre class=\"brush: javascript\">\nfunction foo(x: any) {\n    \/\/ ...\n}\n<\/pre>\n<p>\u5047\u8a2d\u6211\u5011\u78ba\u5b9a\u8a72\u53c3\u6578\u7684\u985e\u578b\u662f <code>string<\/code>\uff0c\u90a3\u9ebc\u6211\u5011\u53ef\u4ee5\u4f7f\u7528\u7c7b\u578b\u5b88\u536b\u4f86\u6539\u8b8a\u985e\u578b\u6aa2\u67e5\u5668\u5c0d\u8a72\u53c3\u6578\u7684\u63a8\u65b7\u7d50\u679c\uff1a<\/p>\n<pre class=\"brush: javascript\">\nfunction foo(x: any) {\n    \/\/ \u7c7b\u578b\u5b88\u536b\n    if (typeof x === 'string') {\n        \/\/ x \u7684\u985e\u578b\u88ab\u63a8\u65b7\u70ba string\n    }\n    \/\/ ...\n}\n<\/pre>\n<p>\u901a\u904e\u7c7b\u578b\u5b88\u536b\uff0c\u6211\u5011\u53ef\u4ee5\u6539\u8b8a\u985e\u578b\u6aa2\u67e5\u5668\u5c0d\u8a72\u53c3\u6578\u7684\u63a8\u65b7\u7d50\u679c\uff0c\u4f7f\u5f97\u8a72\u53c3\u6578\u7684\u985e\u578b\u88ab\u63a8\u65b7\u70ba <code>string<\/code>\u3002<\/p>\n<h2>\u6bd4\u8f03<\/h2>\n<p>\u7c7b\u578b\u65ad\u8a00\u548c\u7c7b\u578b\u5b88\u536b\u90fd\u53ef\u4ee5\u8b93\u958b\u767c\u8005\u5728\u4e0d\u6539\u8b8a\u985e\u578b\u6aa2\u67e5\u884c\u70ba\u7684\u60c5\u6cc1\u4e0b\uff0c\u6539\u8b8a\u985e\u578b\u6aa2\u67e5\u5668\u5c0d\u67d0\u500b\u8868\u9054\u5f0f\u7684\u63a8\u65b7\u7d50\u679c\u3002<\/p>\n<p>\u4e0d\u540c\u4e4b\u8655\u5728\u65bc\uff0c\u7c7b\u578b\u65ad\u8a00\u662f\u4e00\u7a2e\u975c\u614b\u7684\u6280\u8853\uff0c\u5b83\u53ea\u80fd\u6539\u8b8a\u985e\u578b\u6aa2\u67e5\u5668\u5c0d\u67d0\u500b\u8868\u9054\u5f0f\u7684\u63a8\u65b7\u7d50\u679c\uff0c\u800c\u4e0d\u80fd\u6539\u8b8a\u985e\u578b\u6aa2\u67e5\u5668\u5c0d\u67d0\u500b\u8868\u9054\u5f0f\u7684\u63a8\u65b7\u7d50\u679c\u3002<\/p>\n<p>\u800c\u7c7b\u578b\u5b88\u536b\u5247\u662f\u4e00\u7a2e\u52d5\u614b\u7684\u6280\u8853\uff0c\u5b83\u53ef\u4ee5\u6839\u64da\u67d0\u500b\u8868\u9054\u5f0f\u7684\u503c\u4f86\u6539\u8b8a\u985e\u578b\u6aa2\u67e5\u5668\u5c0d\u8a72\u8868\u9054\u5f0f\u7684\u63a8\u65b7\u7d50\u679c\u3002<\/p>\n<h2>\u7e3d\u7d50<\/h2>\n<p>\u672c\u6587\u4ecb\u7d39\u4e86 TypeScript \u4e2d\u7684\u7c7b\u578b\u65ad\u8a00\u548c\u7c7b\u578b\u5b88\u536b\uff0c\u4ee5\u53ca\u5b83\u5011\u4e4b\u9593\u7684\u6bd4\u8f03\u3002\u7c7b\u578b\u65ad\u8a00\u662f\u4e00\u7a2e\u975c\u614b\u7684\u6280\u8853\uff0c\u53ef\u4ee5\u6539\u8b8a\u985e\u578b\u6aa2\u67e5\u5668\u5c0d\u67d0\u500b\u8868\u9054\u5f0f\u7684\u63a8\u65b7\u7d50\u679c\uff1b\u800c\u7c7b\u578b\u5b88\u536b\u5247\u662f\u4e00\u7a2e\u52d5\u614b\u7684\u6280\u8853\uff0c\u53ef\u4ee5\u6839\u64da\u67d0\u500b\u8868\u9054\u5f0f\u7684\u503c\u4f86\u6539\u8b8a\u985e\u578b\u6aa2\u67e5\u5668\u5c0d\u8a72\u8868\u9054\u5f0f\u7684\u63a8\u65b7\u7d50\u679c\u3002<\/p>\n","protected":false},"excerpt":{"rendered":"<p>\u6587\u7ae0\u6458\u8981\uff1a\u672c\u6587\u5c07\u6df1\u5165\u63a2\u8a0eTypeScript\u4e2d\u7c7b\u578b\u65ad\u8a00\u548c\u7c7b\u578b\u5b88\u536b\u7684\u6bd4\u8f83\uff0c\u8a73\u7d30\u4ecb\u7d39\u5169\u8005\u7684\u529f\u80fd\uff0c\u4e26\u6bd4\u8f03\u5169\u8005\u7684\u512a\u7f3a\u9ede\uff0c\u4ee5\u4fbf\u958b\u767c\u8005\u80fd\u5920\u66f4\u597d\u5730\u9078\u64c7\u9069\u5408\u81ea\u5df1\u7684\u65b9\u6848\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-4898","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-1h0","jetpack_sharing_enabled":true,"_links":{"self":[{"href":"https:\/\/badgameshow.com\/steven\/wp-json\/wp\/v2\/posts\/4898","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=4898"}],"version-history":[{"count":1,"href":"https:\/\/badgameshow.com\/steven\/wp-json\/wp\/v2\/posts\/4898\/revisions"}],"predecessor-version":[{"id":4899,"href":"https:\/\/badgameshow.com\/steven\/wp-json\/wp\/v2\/posts\/4898\/revisions\/4899"}],"wp:attachment":[{"href":"https:\/\/badgameshow.com\/steven\/wp-json\/wp\/v2\/media?parent=4898"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/badgameshow.com\/steven\/wp-json\/wp\/v2\/categories?post=4898"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/badgameshow.com\/steven\/wp-json\/wp\/v2\/tags?post=4898"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}