{"id":3100,"date":"2024-11-10T17:29:17","date_gmt":"2024-11-10T09:29:17","guid":{"rendered":"https:\/\/fwq.ai\/blog\/3100\/"},"modified":"2024-11-10T17:29:17","modified_gmt":"2024-11-10T09:29:17","slug":"typescript%e7%b1%bb%e5%9e%8b%e4%ba%a4%e9%9b%86","status":"publish","type":"post","link":"https:\/\/fwq.ai\/blog\/3100\/","title":{"rendered":"typescript\u7c7b\u578b\u4ea4\u96c6"},"content":{"rendered":"<blockquote><p>\n  typescript \u7c7b\u578b\u4ea4\u96c6\u5141\u8bb8\u5c06\u591a\u4e2a\u7c7b\u578b\u5408\u5e76\u6210\u4e00\u4e2a\u65b0\u7c7b\u578b\uff0c\u5305\u542b\u539f\u59cb\u7c7b\u578b\u7684\u5171\u6027\u3002\u4f7f\u7528 &amp; \u8fd0\u7b97\u7b26\u521b\u5efa\u7c7b\u578b\u4ea4\u96c6\uff0c\u4f8b\u5982\uff1atype combinedtype = type1 &amp; type2;\u3002\u7c7b\u578b\u4ea4\u96c6\u4f18\u70b9\u5305\u62ec\u4ee3\u7801\u91cd\u7528\u3001\u63d0\u9ad8\u53ef\u8bfb\u6027\u3001\u907f\u514d\u7c7b\u578b\u9519\u8bef\u3002\u4f8b\u5982\uff0c\u521b\u5efa manager \u7c7b\u578b\u7ee7\u627f person \u548c employee \u7c7b\u578b\uff1atype manager = person &amp; type2;\u3002\u8fd9\u6837\uff0cmanager \u5bf9\u8c61\u5177\u6709 person \u548c employee \u7c7b\u578b\u7684\u6240\u6709\u5c5e\u6027\u3002\u7c7b\u578b\u4ea4\u96c6\u63d0\u4f9b\u4e86\u4e00\u79cd\u5f3a\u5927\u800c\u7075\n<\/p><\/blockquote>\n<p><img decoding=\"async\" src=\"https:\/\/img.php.cn\/upload\/article\/202411\/07\/2024110723362940702.jpg\" class=\"aligncenter\" title=\"typescript\u7c7b\u578b\u4ea4\u96c6\u63d2\u56fe\" alt=\"typescript\u7c7b\u578b\u4ea4\u96c6\u63d2\u56fe\" \/><\/p>\n<p><strong>TypeScript \u7c7b\u578b\u4ea4\u96c6<\/strong><\/p>\n<p><strong>\u4ec0\u4e48\u662f TypeScript \u7c7b\u578b\u4ea4\u96c6\uff1f<\/strong><\/p>\n<p>\u7c7b\u578b\u4ea4\u96c6\u662f\u4e00\u79cd TypeScript \u7279\u6027\uff0c\u5b83\u5141\u8bb8\u5c06\u591a\u4e2a\u7c7b\u578b\u5408\u5e76\u6210\u4e00\u4e2a\u65b0\u7684\u7c7b\u578b\uff0c\u8be5\u7c7b\u578b\u5305\u542b\u539f\u59cb\u7c7b\u578b\u7684\u5171\u6027\u3002<\/p>\n<p><strong>\u5982\u4f55\u521b\u5efa\u7c7b\u578b\u4ea4\u96c6\uff1f<\/strong><\/p>\n<p>\u4f7f\u7528 &amp; \u8fd0\u7b97\u7b26\u53ef\u4ee5\u521b\u5efa\u7c7b\u578b\u4ea4\u96c6\uff1a<\/p>\n<pre>type CombinedType = Type1 &amp; Type2;<\/pre>\n<p> \u767b\u5f55\u540e\u590d\u5236 <\/p>\n<p><strong>\u7c7b\u578b\u4ea4\u96c6\u7684\u4f18\u70b9<\/strong><\/p>\n<ul>\n<li> <strong>\u4ee3\u7801\u91cd\u7528\uff1a<\/strong>TypeScript \u7c7b\u578b\u4ea4\u96c6\u53ef\u4ee5\u5141\u8bb8\u60a8\u91cd\u7528\u4e0d\u540c\u7c7b\u578b\u4e4b\u95f4\u7684\u5171\u540c\u5c5e\u6027\uff0c\u907f\u514d\u91cd\u590d\u7f16\u7801\u3002<\/li>\n<li> <strong>\u63d0\u9ad8\u53ef\u8bfb\u6027\uff1a<\/strong>\u7c7b\u578b\u4ea4\u96c6\u53ef\u4ee5\u4f7f\u4ee3\u7801\u66f4\u6613\u4e8e\u9605\u8bfb\u548c\u7406\u89e3\uff0c\u56e0\u4e3a\u5b83\u660e\u786e\u8bf4\u660e\u4e86\u4e0d\u540c\u7c7b\u578b\u7684\u5173\u7cfb\u3002<\/li>\n<li> <strong>\u907f\u514d\u7c7b\u578b\u9519\u8bef\uff1a<\/strong>\u901a\u8fc7\u5c06\u591a\u4e2a\u7c7b\u578b\u5408\u5e76\uff0c\u7c7b\u578b\u4ea4\u96c6\u53ef\u4ee5\u5e2e\u52a9\u9632\u6b62\u7c7b\u578b\u9519\u8bef\uff0c\u56e0\u4e3a\u5b83\u786e\u4fdd\u4e86\u503c\u6ee1\u8db3\u6240\u6709\u539f\u59cb\u7c7b\u578b\u7684\u8981\u6c42\u3002<\/li>\n<\/ul>\n<p><strong>\u793a\u4f8b<\/strong><\/p>\n<p>\u4f8b\u5982\uff0c\u6211\u4eec\u6709\u4ee5\u4e0b\u4e24\u4e2a\u7c7b\u578b\uff1a<\/p>\n<pre>interface Person {\n  name: string;\n}\n\ninterface Employee {\n  salary: number;\n}<\/pre>\n<p> \u767b\u5f55\u540e\u590d\u5236 <\/p>\n<p>\u6211\u4eec\u53ef\u4ee5\u4f7f\u7528\u7c7b\u578b\u4ea4\u96c6\u521b\u5efa Manager \u7c7b\u578b\uff0c\u5b83\u7ee7\u627f\u4e86 Person \u548c Employee \u7c7b\u578b\uff1a<\/p>\n<pre>type Manager = Person &amp; Employee;\n\nconst manager: Manager = {\n  name: \"John Smith\",\n  salary: 100000,\n};<\/pre>\n<p> \u767b\u5f55\u540e\u590d\u5236 <\/p>\n<p>\u73b0\u5728\uff0cmanager \u5bf9\u8c61\u65e2\u5177\u6709 name \u5c5e\u6027\u53c8\u5177\u6709 salary \u5c5e\u6027\u3002<\/p>\n<p><strong>\u7ed3\u8bba<\/strong><\/p>\n<p>TypeScript \u7c7b\u578b\u4ea4\u96c6\u63d0\u4f9b\u4e86\u4e00\u79cd\u5f3a\u5927\u4e14\u7075\u6d3b\u7684\u65b9\u5f0f\u6765\u5408\u5e76\u4e0d\u540c\u7c7b\u578b\uff0c\u63d0\u9ad8\u4ee3\u7801\u91cd\u7528\u6027\u3001\u53ef\u8bfb\u6027\u548c\u5b89\u5168\u6027\u3002\u901a\u8fc7\u7406\u89e3\u5982\u4f55\u521b\u5efa\u548c\u4f7f\u7528\u7c7b\u578b\u4ea4\u96c6\uff0c\u60a8\u53ef\u4ee5\u7f16\u5199\u66f4\u6e05\u6670\u3001\u66f4\u5065\u58ee\u7684 TypeScript \u4ee3\u7801\u3002<\/p>\n<p>\u4ee5\u4e0a\u5c31\u662f\u7c7b\u578b\u4ea4\u96c6\u7684\u8be6\u7ec6\u5185\u5bb9\uff0c\u66f4\u591a\u8bf7\u5173\u6ce8\u7c73\u4e91\u5176\u5b83\u76f8\u5173\u6587\u7ae0\uff01<\/p>\n","protected":false},"excerpt":{"rendered":"<p>typescript \u7c7b\u578b\u4ea4\u96c6\u5141\u8bb8\u5c06\u591a\u4e2a\u7c7b\u578b\u5408\u5e76\u6210\u4e00\u4e2a\u65b0\u7c7b\u578b\uff0c\u5305\u542b\u539f\u59cb\u7c7b\u578b\u7684\u5171\u6027\u3002\u4f7f\u7528 &amp; \u8fd0\u7b97\u7b26\u521b\u5efa\u7c7b\u578b\u4ea4\u96c6\uff0c\u4f8b\u5982\uff1atype combinedtype = type1 &amp; type2;\u3002\u7c7b\u578b\u4ea4\u96c6\u4f18\u70b9\u5305\u62ec\u4ee3\u7801\u91cd\u7528\u3001\u63d0\u9ad8\u53ef\u8bfb\u6027\u3001\u907f\u514d\u7c7b\u578b\u9519\u8bef\u3002\u4f8b\u5982\uff0c\u521b\u5efa manager \u7c7b\u578b\u7ee7\u627f person \u548c employee \u7c7b\u578b\uff1atype manager = person &amp; type2;\u3002\u8fd9\u6837\uff0cmanager \u5bf9\u8c61\u5177\u6709 person \u548c employee \u7c7b\u578b\u7684\u6240\u6709\u5c5e\u6027\u3002\u7c7b\u578b\u4ea4\u96c6\u63d0\u4f9b\u4e86\u4e00\u79cd\u5f3a\u5927\u800c\u7075 TypeScript \u7c7b\u578b\u4ea4\u96c6 \u4ec0\u4e48\u662f TypeScript \u7c7b\u578b\u4ea4\u96c6\uff1f \u7c7b\u578b\u4ea4\u96c6\u662f\u4e00\u79cd TypeScript \u7279\u6027\uff0c\u5b83\u5141\u8bb8\u5c06\u591a\u4e2a\u7c7b\u578b\u5408\u5e76\u6210\u4e00\u4e2a\u65b0\u7684\u7c7b\u578b\uff0c\u8be5\u7c7b\u578b\u5305\u542b\u539f\u59cb\u7c7b\u578b\u7684\u5171\u6027\u3002 \u5982\u4f55\u521b\u5efa\u7c7b\u578b\u4ea4\u96c6\uff1f \u4f7f\u7528 &amp; \u8fd0\u7b97\u7b26\u53ef\u4ee5\u521b\u5efa\u7c7b\u578b\u4ea4\u96c6\uff1a type CombinedType = Type1 &amp; Type2; \u767b\u5f55\u540e\u590d\u5236 \u7c7b\u578b\u4ea4\u96c6\u7684\u4f18\u70b9 \u4ee3\u7801\u91cd\u7528\uff1aTypeScript \u7c7b\u578b\u4ea4\u96c6\u53ef\u4ee5\u5141\u8bb8\u60a8\u91cd\u7528\u4e0d\u540c\u7c7b\u578b\u4e4b\u95f4\u7684\u5171\u540c\u5c5e\u6027\uff0c\u907f\u514d\u91cd\u590d\u7f16\u7801\u3002 \u63d0\u9ad8\u53ef\u8bfb\u6027\uff1a\u7c7b\u578b\u4ea4\u96c6\u53ef\u4ee5\u4f7f\u4ee3\u7801\u66f4\u6613\u4e8e\u9605\u8bfb\u548c\u7406\u89e3\uff0c\u56e0\u4e3a\u5b83\u660e\u786e\u8bf4\u660e\u4e86\u4e0d\u540c\u7c7b\u578b\u7684\u5173\u7cfb\u3002 \u907f\u514d\u7c7b\u578b\u9519\u8bef\uff1a\u901a\u8fc7\u5c06\u591a\u4e2a\u7c7b\u578b\u5408\u5e76\uff0c\u7c7b\u578b\u4ea4\u96c6\u53ef\u4ee5\u5e2e\u52a9\u9632\u6b62\u7c7b\u578b\u9519\u8bef\uff0c\u56e0\u4e3a\u5b83\u786e\u4fdd\u4e86\u503c\u6ee1\u8db3\u6240\u6709\u539f\u59cb\u7c7b\u578b\u7684\u8981\u6c42\u3002 \u793a\u4f8b \u4f8b\u5982\uff0c\u6211\u4eec\u6709\u4ee5\u4e0b\u4e24\u4e2a\u7c7b\u578b\uff1a interface Person { name: [&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-3100","post","type-post","status-publish","format-standard","hentry","category-16"],"_links":{"self":[{"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/posts\/3100","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=3100"}],"version-history":[{"count":0,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/posts\/3100\/revisions"}],"wp:attachment":[{"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/media?parent=3100"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/categories?post=3100"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/tags?post=3100"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}