{"id":4930,"date":"2023-01-05T11:20:45","date_gmt":"2023-01-05T03:20:45","guid":{"rendered":"https:\/\/badgameshow.com\/steven\/?p=4930"},"modified":"2023-01-05T11:20:45","modified_gmt":"2023-01-05T03:20:45","slug":"%e5%ad%b8%e7%bf%92typescript%e4%b8%ad%e7%9a%84%e5%87%bd%e6%95%b8%e9%87%8d%e8%bc%89%ef%bc%9a%e6%b7%b1%e5%85%a5%e4%ba%86%e8%a7%a3%e5%87%bd%e6%95%b8%e7%9a%84%e5%8a%9f%e8%83%bd%e8%88%87%e6%87%89%e7%94%a8","status":"publish","type":"post","link":"https:\/\/badgameshow.com\/steven\/typescript\/%e5%ad%b8%e7%bf%92typescript%e4%b8%ad%e7%9a%84%e5%87%bd%e6%95%b8%e9%87%8d%e8%bc%89%ef%bc%9a%e6%b7%b1%e5%85%a5%e4%ba%86%e8%a7%a3%e5%87%bd%e6%95%b8%e7%9a%84%e5%8a%9f%e8%83%bd%e8%88%87%e6%87%89%e7%94%a8\/","title":{"rendered":"\u5b78\u7fd2TypeScript\u4e2d\u7684\u51fd\u6578\u91cd\u8f09\uff1a\u6df1\u5165\u4e86\u89e3\u51fd\u6578\u7684\u529f\u80fd\u8207\u61c9\u7528"},"content":{"rendered":"<p><meta name=\"keywords\" content=\"TypeScript, \u51fd\u6578\u91cd\u8f09, Function Overloading\"><\/p>\n<h1>TypeScript \u51fd\u6578\u91cd\u8f09(Function Overloading)<\/h1>\n<p>TypeScript \u662f\u4e00\u7a2e\u5f37\u578b\u5225\u7684 JavaScript \u8a9e\u8a00\uff0c\u5b83\u652f\u63f4\u51fd\u6578\u91cd\u8f09\uff08Function Overloading\uff09\uff0c\u53ef\u4ee5\u8b93\u958b\u767c\u8005\u5728\u5b9a\u7fa9\u51fd\u6578\u6642\uff0c\u6307\u5b9a\u4e0d\u540c\u7684\u53c3\u6578\u578b\u5225\uff0c\u4ee5\u53ca\u4e0d\u540c\u7684\u56de\u50b3\u578b\u5225\u3002<\/p>\n<h2>\u4ec0\u9ebc\u662f\u51fd\u6578\u91cd\u8f09\uff1f<\/h2>\n<p>\u51fd\u6578\u91cd\u8f09\uff08Function Overloading\uff09\u662f\u4e00\u7a2e\u7a0b\u5f0f\u8a2d\u8a08\u6280\u8853\uff0c\u5b83\u5141\u8a31\u958b\u767c\u8005\u5728\u5b9a\u7fa9\u51fd\u6578\u6642\uff0c\u6307\u5b9a\u4e0d\u540c\u7684\u53c3\u6578\u578b\u5225\uff0c\u4ee5\u53ca\u4e0d\u540c\u7684\u56de\u50b3\u578b\u5225\u3002<\/p>\n<p>\u8209\u500b\u4f8b\u5b50\uff0c\u5047\u8a2d\u6211\u5011\u6709\u4e00\u500b\u51fd\u6578 <code>add()<\/code>\uff0c\u5b83\u53ef\u4ee5\u63a5\u53d7\u5169\u500b\u53c3\u6578\uff0c\u4e26\u4e14\u56de\u50b3\u5169\u500b\u53c3\u6578\u7684\u548c\uff1a<\/p>\n<pre class=\"brush: typescript\">\nfunction add(a: number, b: number): number {\n  return a + b;\n}\n<\/pre>\n<p>\u9019\u500b\u51fd\u6578\u53ea\u80fd\u63a5\u53d7\u5169\u500b\u6578\u5b57\u53c3\u6578\uff0c\u4e26\u4e14\u56de\u50b3\u4e00\u500b\u6578\u5b57\u3002<\/p>\n<p>\u5982\u679c\u6211\u5011\u60f3\u8981\u8b93 <code>add()<\/code> \u51fd\u6578\u53ef\u4ee5\u63a5\u53d7\u5169\u500b\u5b57\u4e32\u53c3\u6578\uff0c\u4e26\u4e14\u56de\u50b3\u4e00\u500b\u5b57\u4e32\uff0c\u6211\u5011\u53ef\u4ee5\u4f7f\u7528\u51fd\u6578\u91cd\u8f09\uff08Function Overloading\uff09\u4f86\u5b9a\u7fa9\u4e00\u500b\u65b0\u7684 <code>add()<\/code> \u51fd\u6578\uff1a<\/p>\n<pre class=\"brush: typescript\">\nfunction add(a: string, b: string): string {\n  return a + b;\n}\n<\/pre>\n<p>\u9019\u6a23\uff0c\u6211\u5011\u5c31\u53ef\u4ee5\u540c\u6642\u4f7f\u7528\u5169\u500b\u4e0d\u540c\u7684 <code>add()<\/code> \u51fd\u6578\uff0c\u4e00\u500b\u63a5\u53d7\u5169\u500b\u6578\u5b57\u53c3\u6578\uff0c\u53e6\u4e00\u500b\u63a5\u53d7\u5169\u500b\u5b57\u4e32\u53c3\u6578\u3002<\/p>\n<h2>\u5982\u4f55\u4f7f\u7528 TypeScript \u4f86\u5be6\u73fe\u51fd\u6578\u91cd\u8f09\uff1f<\/h2>\n<p>TypeScript \u652f\u63f4\u51fd\u6578\u91cd\u8f09\uff08Function Overloading\uff09\uff0c\u53ef\u4ee5\u8b93\u958b\u767c\u8005\u5728\u5b9a\u7fa9\u51fd\u6578\u6642\uff0c\u6307\u5b9a\u4e0d\u540c\u7684\u53c3\u6578\u578b\u5225\uff0c\u4ee5\u53ca\u4e0d\u540c\u7684\u56de\u50b3\u578b\u5225\u3002<\/p>\n<p>\u8209\u500b\u4f8b\u5b50\uff0c\u5047\u8a2d\u6211\u5011\u6709\u4e00\u500b\u51fd\u6578 <code>add()<\/code>\uff0c\u5b83\u53ef\u4ee5\u63a5\u53d7\u5169\u500b\u53c3\u6578\uff0c\u4e26\u4e14\u56de\u50b3\u5169\u500b\u53c3\u6578\u7684\u548c\uff1a<\/p>\n<pre class=\"brush: typescript\">\nfunction add(a: number, b: number): number {\n  return a + b;\n}\n<\/pre>\n<p>\u9019\u500b\u51fd\u6578\u53ea\u80fd\u63a5\u53d7\u5169\u500b\u6578\u5b57\u53c3\u6578\uff0c\u4e26\u4e14\u56de\u50b3\u4e00\u500b\u6578\u5b57\u3002<\/p>\n<p>\u5982\u679c\u6211\u5011\u60f3\u8981\u8b93 <code>add()<\/code> \u51fd\u6578\u53ef\u4ee5\u63a5\u53d7\u5169\u500b\u5b57\u4e32\u53c3\u6578\uff0c\u4e26\u4e14\u56de\u50b3\u4e00\u500b\u5b57\u4e32\uff0c\u6211\u5011\u53ef\u4ee5\u4f7f\u7528 TypeScript \u7684\u51fd\u6578\u91cd\u8f09\uff08Function Overloading\uff09\u4f86\u5b9a\u7fa9\u4e00\u500b\u65b0\u7684 <code>add()<\/code> \u51fd\u6578\uff1a<\/p>\n<pre class=\"brush: typescript\">\nfunction add(a: string, b: string): string;\nfunction add(a: number, b: number): number;\n\nfunction add(a: any, b: any): any {\n  return a + b;\n}\n<\/pre>\n<p>\u9019\u6a23\uff0c\u6211\u5011\u5c31\u53ef\u4ee5\u540c\u6642\u4f7f\u7528\u5169\u500b\u4e0d\u540c\u7684 <code>add()<\/code> \u51fd\u6578\uff0c\u4e00\u500b\u63a5\u53d7\u5169\u500b\u6578\u5b57\u53c3\u6578\uff0c\u53e6\u4e00\u500b\u63a5\u53d7\u5169\u500b\u5b57\u4e32\u53c3\u6578\u3002<\/p>\n<h2>\u7e3d\u7d50<\/h2>\n<p>TypeScript \u652f\u63f4\u51fd\u6578\u91cd\u8f09\uff08Function Overloading\uff09\uff0c\u53ef\u4ee5\u8b93\u958b\u767c\u8005\u5728\u5b9a\u7fa9\u51fd\u6578\u6642\uff0c\u6307\u5b9a\u4e0d\u540c\u7684\u53c3\u6578\u578b\u5225\uff0c\u4ee5\u53ca\u4e0d\u540c\u7684\u56de\u50b3\u578b\u5225\u3002\u9019\u6a23\u53ef\u4ee5\u8b93\u958b\u767c\u8005\u66f4\u52a0\u6709\u6548\u7387\u7684\u958b\u767c\u51fd\u6578\uff0c\u4e26\u4e14\u6e1b\u5c11\u51fd\u6578\u547d\u540d\u6df7\u4e82\u7684\u554f\u984c\u3002<\/p>\n","protected":false},"excerpt":{"rendered":"<p>\u6587\u7ae0\u6458\u8981\uff1aTypeScript\u4e2d\u7684\u51fd\u6578\u91cd\u8f09\u662f\u4e00\u7a2e\u6280\u8853\uff0c\u53ef\u4ee5\u8b93\u958b\u767c\u8005\u5728\u540c\u4e00\u500b\u51fd\u6578\u4e2d\u5b9a\u7fa9\u591a\u500b\u4e0d\u540c\u7684\u53c3\u6578\u7d44\u5408\uff0c\u4ee5\u6eff\u8db3\u4e0d\u540c\u7684\u9700\u6c42\u3002\u672c\u6587\u5c07\u6df1\u5165\u89e3\u91cb\u51fd\u6578\u91cd\u8f09\u7684\u6982\u5ff5\uff0c\u4e26\u63d0\u4f9b\u4e00\u4e9b\u5be6\u7528\u7684\u61c9\u7528\u6848\u4f8b\uff0c\u8b93\u958b\u767c\u8005\u66f4\u52a0\u4e86\u89e3\u51fd\u6578\u91cd\u8f09\u7684\u529f\u80fd\u8207\u61c9\u7528\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-4930","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-1hw","jetpack_sharing_enabled":true,"_links":{"self":[{"href":"https:\/\/badgameshow.com\/steven\/wp-json\/wp\/v2\/posts\/4930","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=4930"}],"version-history":[{"count":1,"href":"https:\/\/badgameshow.com\/steven\/wp-json\/wp\/v2\/posts\/4930\/revisions"}],"predecessor-version":[{"id":4931,"href":"https:\/\/badgameshow.com\/steven\/wp-json\/wp\/v2\/posts\/4930\/revisions\/4931"}],"wp:attachment":[{"href":"https:\/\/badgameshow.com\/steven\/wp-json\/wp\/v2\/media?parent=4930"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/badgameshow.com\/steven\/wp-json\/wp\/v2\/categories?post=4930"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/badgameshow.com\/steven\/wp-json\/wp\/v2\/tags?post=4930"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}