{"id":4990,"date":"2023-01-05T11:33:51","date_gmt":"2023-01-05T03:33:51","guid":{"rendered":"https:\/\/badgameshow.com\/steven\/?p=4990"},"modified":"2023-01-05T11:33:51","modified_gmt":"2023-01-05T03:33:51","slug":"%e4%ba%86%e8%a7%a3%e5%a6%82%e4%bd%95%e5%88%a9%e7%94%a8typescript%e6%8e%a5%e5%8f%a3interfaces%e7%9a%84%e7%b9%bc%e6%89%bf","status":"publish","type":"post","link":"https:\/\/badgameshow.com\/steven\/typescript\/%e4%ba%86%e8%a7%a3%e5%a6%82%e4%bd%95%e5%88%a9%e7%94%a8typescript%e6%8e%a5%e5%8f%a3interfaces%e7%9a%84%e7%b9%bc%e6%89%bf\/","title":{"rendered":"\u4e86\u89e3\u5982\u4f55\u5229\u7528TypeScript\u63a5\u53e3(interfaces)\u7684\u7e7c\u627f"},"content":{"rendered":"<p><meta name=\"keywords\" content=\"TypeScript, Interfaces, \u7e7c\u627f\"><\/p>\n<h1>TypeScript \u63a5\u53e3(interfaces)\u7684\u7e7c\u627f<\/h1>\n<p>TypeScript \u662f\u4e00\u7a2e JavaScript \u7684\u8d85\u96c6\uff0c\u5b83\u63d0\u4f9b\u4e86\u985e\u578b\u7cfb\u7d71\u548c\u5c0d ES6 \u7684\u652f\u6301\uff0c\u4f7f\u958b\u767c\u8005\u80fd\u5920\u66f4\u8f15\u9b06\u5730\u958b\u767c\u51fa\u66f4\u5065\u58ef\u7684 JavaScript \u7a0b\u5f0f\u78bc\u3002\u5176\u4e2d\u4e00\u500b\u91cd\u8981\u7684\u529f\u80fd\u5c31\u662f\u63a5\u53e3(interfaces)\u7684\u7e7c\u627f\uff0c\u5b83\u53ef\u4ee5\u8b93\u958b\u767c\u8005\u66f4\u8f15\u9b06\u5730\u5b9a\u7fa9\u548c\u4f7f\u7528\u63a5\u53e3\u3002<\/p>\n<p><!--more--><\/p>\n<p>\u63a5\u53e3(interfaces)\u7684\u7e7c\u627f\u662f\u6307\uff0c\u4e00\u500b\u63a5\u53e3\u53ef\u4ee5\u7e7c\u627f\u53e6\u4e00\u500b\u63a5\u53e3\uff0c\u4e26\u4e14\u53ef\u4ee5\u7e7c\u627f\u591a\u500b\u63a5\u53e3\u3002\u9019\u6a23\u4e00\u4f86\uff0c\u958b\u767c\u8005\u5c31\u53ef\u4ee5\u66f4\u8f15\u9b06\u5730\u5b9a\u7fa9\u63a5\u53e3\uff0c\u4e26\u4e14\u53ef\u4ee5\u66f4\u8f15\u9b06\u5730\u4f7f\u7528\u63a5\u53e3\u3002<\/p>\n<p>\u8209\u500b\u4f8b\u5b50\u4f86\u8aaa\uff0c\u5047\u8a2d\u6211\u5011\u6709\u4e00\u500b\u63a5\u53e3\u53eb\u505a <span style=\"font-weight: bold;\">Animal<\/span>\uff0c\u5b83\u6709\u4e00\u500b\u65b9\u6cd5\u53eb\u505a <span style=\"font-weight: bold;\">eat()<\/span>\uff0c\u5b83\u53ef\u4ee5\u8b93\u52d5\u7269\u5403\u6771\u897f\uff1a<\/p>\n<pre class=\"brush: typescript\">\ninterface Animal {\n    eat(): void;\n}\n<\/pre>\n<p>\u73fe\u5728\uff0c\u5047\u8a2d\u6211\u5011\u60f3\u8981\u5b9a\u7fa9\u4e00\u500b\u65b0\u7684\u63a5\u53e3\u53eb\u505a <span style=\"font-weight: bold;\">Dog<\/span>\uff0c\u5b83\u6709\u4e00\u500b\u65b9\u6cd5\u53eb\u505a <span style=\"font-weight: bold;\">bark()<\/span>\uff0c\u5b83\u53ef\u4ee5\u8b93\u72d7\u53eb\uff1a<\/p>\n<pre class=\"brush: typescript\">\ninterface Dog {\n    bark(): void;\n}\n<\/pre>\n<p>\u73fe\u5728\uff0c\u6211\u5011\u53ef\u4ee5\u4f7f\u7528\u63a5\u53e3\u7684\u7e7c\u627f\u4f86\u5b9a\u7fa9\u4e00\u500b\u65b0\u7684\u63a5\u53e3\uff0c\u8a72\u63a5\u53e3\u53ef\u4ee5\u540c\u6642\u7e7c\u627f <span style=\"font-weight: bold;\">Animal<\/span> \u548c <span style=\"font-weight: bold;\">Dog<\/span> \u63a5\u53e3\uff1a<\/p>\n<pre class=\"brush: typescript\">\ninterface DogAnimal extends Animal, Dog {\n\n}\n<\/pre>\n<p>\u9019\u6a23\u4e00\u4f86\uff0c\u6211\u5011\u5c31\u53ef\u4ee5\u5b9a\u7fa9\u4e00\u500b\u65b0\u7684\u63a5\u53e3\uff0c\u8a72\u63a5\u53e3\u53ef\u4ee5\u540c\u6642\u4f7f\u7528 <span style=\"font-weight: bold;\">Animal<\/span> \u548c <span style=\"font-weight: bold;\">Dog<\/span> \u63a5\u53e3\u4e2d\u7684\u65b9\u6cd5\uff1a<\/p>\n<pre class=\"brush: typescript\">\nlet dogAnimal: DogAnimal = {\n    eat(): void {\n        \/\/ eat something\n    },\n    bark(): void {\n        \/\/ bark something\n    }\n};\n<\/pre>\n<p>\u9019\u6a23\u4e00\u4f86\uff0c\u6211\u5011\u5c31\u53ef\u4ee5\u66f4\u8f15\u9b06\u5730\u5b9a\u7fa9\u548c\u4f7f\u7528\u63a5\u53e3\uff0c\u800c\u4e0d\u9700\u8981\u91cd\u8907\u5b9a\u7fa9\u76f8\u540c\u7684\u65b9\u6cd5\u3002<\/p>\n<p>\u7e3d\u7d50\u4f86\u8aaa\uff0cTypeScript \u63a5\u53e3(interfaces)\u7684\u7e7c\u627f\u53ef\u4ee5\u8b93\u958b\u767c\u8005\u66f4\u8f15\u9b06\u5730\u5b9a\u7fa9\u548c\u4f7f\u7528\u63a5\u53e3\uff0c\u800c\u4e0d\u9700\u8981\u91cd\u8907\u5b9a\u7fa9\u76f8\u540c\u7684\u65b9\u6cd5\u3002\u5b83\u53ef\u4ee5\u8b93\u958b\u767c\u8005\u66f4\u8f15\u9b06\u5730\u958b\u767c\u51fa\u66f4\u5065\u58ef\u7684 JavaScript \u7a0b\u5f0f\u78bc\u3002<\/p>\n","protected":false},"excerpt":{"rendered":"<p>\u5b78\u7fd2\u5982\u4f55\u5229\u7528TypeScript\u63a5\u53e3(interfaces)\u7684\u7e7c\u627f\uff0c\u53ef\u4ee5\u8b93\u958b\u767c\u8005\u66f4\u6709\u6548\u7387\u7684\u958b\u767c\u51fa\u66f4\u597d\u7684\u7a0b\u5f0f\u78bc\uff0c\u4e26\u4e14\u66f4\u5bb9\u6613\u7dad\u8b77\u8207\u64f4\u5145\u3002\u672c\u6587\u5c07\u6703\u4ecb\u7d39TypeScript\u63a5\u53e3(interfaces)\u7684\u7e7c\u627f\u7684\u57fa\u672c\u6982\u5ff5\uff0c\u4ee5\u53ca\u5982\u4f55\u5229\u7528\u5b83\u4f86\u958b\u767c\u51fa\u66f4\u597d\u7684\u7a0b\u5f0f\u78bc\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-4990","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-1iu","jetpack_sharing_enabled":true,"_links":{"self":[{"href":"https:\/\/badgameshow.com\/steven\/wp-json\/wp\/v2\/posts\/4990","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=4990"}],"version-history":[{"count":1,"href":"https:\/\/badgameshow.com\/steven\/wp-json\/wp\/v2\/posts\/4990\/revisions"}],"predecessor-version":[{"id":4991,"href":"https:\/\/badgameshow.com\/steven\/wp-json\/wp\/v2\/posts\/4990\/revisions\/4991"}],"wp:attachment":[{"href":"https:\/\/badgameshow.com\/steven\/wp-json\/wp\/v2\/media?parent=4990"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/badgameshow.com\/steven\/wp-json\/wp\/v2\/categories?post=4990"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/badgameshow.com\/steven\/wp-json\/wp\/v2\/tags?post=4990"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}