{"id":3097,"date":"2024-11-10T16:30:07","date_gmt":"2024-11-10T08:30:07","guid":{"rendered":"https:\/\/fwq.ai\/blog\/3097\/"},"modified":"2024-11-10T16:30:07","modified_gmt":"2024-11-10T08:30:07","slug":"typescript%e7%b1%bb%e6%8e%a5%e5%8f%a3%e4%b8%8e%e7%b1%bb%e5%9e%8b%e6%9c%89%e5%93%aa%e4%ba%9b","status":"publish","type":"post","link":"https:\/\/fwq.ai\/blog\/3097\/","title":{"rendered":"typescript\u7c7b\u63a5\u53e3\u4e0e\u7c7b\u578b\u6709\u54ea\u4e9b"},"content":{"rendered":"<blockquote><p>\n  \u7c7b\u63a5\u53e3\u548c\u7c7b\u578b\u662f typescript \u4e2d\u5b9a\u4e49\u7c7b\u7ed3\u6784\u548c\u884c\u4e3a\u7684\u4e24\u79cd\u673a\u5236\u3002\u7c7b\u63a5\u53e3\u7528\u4e8e\u5b9a\u4e49\u7c7b\u7684\u516c\u5171 api\uff0c\u800c\u7c7b\u578b\u7528\u4e8e\u5b9a\u4e49\u7c7b\u7684\u5b8c\u6574\u7ed3\u6784\uff0c\u5305\u62ec\u79c1\u6709\u5b9e\u73b0\u7ec6\u8282\u3002\u4e3b\u8981\u533a\u522b\u5728\u4e8e\u8bbf\u95ee\u6027\uff08\u63a5\u53e3\u4ec5\u516c\u5f00\u7c7b\u6210\u5458\uff0c\u800c\u7c7b\u578b\u516c\u5f00\u5168\u90e8\u6210\u5458\uff09\u3001\u7ee7\u627f\uff08\u63a5\u53e3\u652f\u6301\u591a\u91cd\u7ee7\u627f\uff0c\u800c\u7c7b\u578b\u4ec5\u652f\u6301\u5355\u4e00\u7ee7\u627f\uff09\u548c\u5b9e\u4f8b\u5316\uff08\u63a5\u53e3\u4e0d\u80fd\u76f4\u63a5\u5b9e\u4f8b\u5316\uff0c\u800c\u7c7b\u578b\u53ef\u4ee5\uff09\u3002\u6839\u636e\u9700\u6c42\uff0c\u7c7b\u63a5\u53e3\u9002\u7528\u4e8e\u5b9a\u4e49\u7c7b\u7684\u516c\u5171\u9762\u5411\uff0c\u800c\u7c7b\u578b\u9002\u7528\u4e8e\u5b9a\u4e49\u7c7b\u7684\u5b8c\u6574\u7ed3\u6784\u548c\u884c\u4e3a\u3002\n<\/p><\/blockquote>\n<p><img decoding=\"async\" src=\"https:\/\/img.php.cn\/upload\/article\/202411\/07\/2024110723304088089.jpg\" class=\"aligncenter\" title=\"typescript\u7c7b\u63a5\u53e3\u4e0e\u7c7b\u578b\u6709\u54ea\u4e9b\u63d2\u56fe\" alt=\"typescript\u7c7b\u63a5\u53e3\u4e0e\u7c7b\u578b\u6709\u54ea\u4e9b\u63d2\u56fe\" \/><\/p>\n<h2>TypeScript \u7c7b\u63a5\u53e3\u4e0e\u7c7b\u578b<\/h2>\n<p>TypeScript \u63d0\u4f9b\u4e86\u7c7b\u63a5\u53e3\u548c\u7c7b\u578b\u4e24\u79cd\u673a\u5236\u6765\u5b9a\u4e49\u7c7b\u7684\u5f62\u72b6\u548c\u884c\u4e3a\u3002\u867d\u7136\u5b83\u4eec\u6709\u76f8\u4f3c\u4e4b\u5904\uff0c\u4f46\u5b83\u4eec\u5728\u76ee\u7684\u548c\u4f7f\u7528\u65b9\u5f0f\u4e0a\u5b58\u5728\u5173\u952e\u5dee\u5f02\u3002<\/p>\n<h3>\u7c7b\u63a5\u53e3<\/h3>\n<p><strong>\u76ee\u7684\uff1a<\/strong>\u5b9a\u4e49\u7c7b\u7684\u516c\u5171 API\uff0c\u5305\u62ec\u5176\u5c5e\u6027\u3001\u65b9\u6cd5\u548c\u4e8b\u4ef6\u3002<\/p>\n<p><strong>\u8bed\u6cd5\uff1a<\/strong><\/p>\n<pre>interface InterfaceName {\n  \/\/ \u5c5e\u6027\n  property1: type1;\n  property2: type2;\n  \/\/ \u65b9\u6cd5\n  method1(arg1: type3, arg2: type4): returnType;\n  method2(): void;\n  \/\/ \u4e8b\u4ef6\n  event1: string;\n}<\/pre>\n<p> \u767b\u5f55\u540e\u590d\u5236 <\/p>\n<h3>\u7c7b\u578b<\/h3>\n<p><strong>\u76ee\u7684\uff1a<\/strong>\u5b9a\u4e49\u7c7b\u7684\u5b8c\u6574\u7ed3\u6784\uff0c\u5305\u62ec\u5176\u79c1\u6709\u5b9e\u73b0\u7ec6\u8282\u3002<\/p>\n<p><strong>\u8bed\u6cd5\uff1a<\/strong><\/p>\n<pre>type TypeName = {\n  \/\/ \u5c5e\u6027\n  property1: type1;\n  property2: type2;\n  \/\/ \u65b9\u6cd5\n  method1(arg1: type3, arg2: type4): returnType;\n  method2(): void;\n}<\/pre>\n<p> \u767b\u5f55\u540e\u590d\u5236 <\/p>\n<h3>\u4e3b\u8981\u5dee\u5f02<\/h3>\n<table>\n<thead>\n<tr>\n<th>\u7279\u5f81<\/th>\n<th>\u7c7b\u63a5\u53e3<\/th>\n<th>\u7c7b\u578b<\/th>\n<\/tr>\n<\/thead>\n<tbody>\n<tr>\n<td>\u76ee\u7684<\/td>\n<td>\u5b9a\u4e49\u516c\u5171 API<\/td>\n<td>\u5b9a\u4e49\u5b8c\u6574\u7ed3\u6784<\/td>\n<\/tr>\n<tr>\n<td>\u53ef\u8bbf\u95ee\u6027<\/td>\n<td>\u53ea\u516c\u5f00\u7c7b\u6210\u5458<\/td>\n<td>\u516c\u5f00\u7c7b\u6210\u5458\u548c\u79c1\u6709\u6210\u5458<\/td>\n<\/tr>\n<tr>\n<td>\u7ee7\u627f<\/td>\n<td>\u53ef\u4ee5\u4ece\u591a\u4e2a\u63a5\u53e3\u7ee7\u627f<\/td>\n<td>\u53ea\u80fd\u4ece\u4e00\u4e2a\u7c7b\u578b\u7ee7\u627f<\/td>\n<\/tr>\n<tr>\n<td>\u5b9e\u4f8b\u5316<\/td>\n<td>\u4e0d\u80fd\u76f4\u63a5\u5b9e\u4f8b\u5316<\/td>\n<td>\u53ef\u4ee5\u76f4\u63a5\u5b9e\u4f8b\u5316<\/td>\n<\/tr>\n<tr>\n<td>\u7528\u6cd5<\/td>\n<td>\u7528\u4f5c\u7c7b\u7684\u7ea6\u675f<\/td>\n<td>\u7528\u4f5c\u5bf9\u7c7b\u7684\u5b8c\u5168\u5b9a\u4e49<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<h3>\u7528\u6cd5\u793a\u4f8b<\/h3>\n<p><strong>\u7c7b\u63a5\u53e3\uff1a<\/strong><\/p>\n<pre>interface Person {\n  name: string;\n  age: number;\n\n  greet(): void;\n}\n\nclass Employee implements Person {\n  \/\/ ...\n}<\/pre>\n<p> \u767b\u5f55\u540e\u590d\u5236 <\/p>\n<p><strong>\u7c7b\u578b\uff1a<\/strong><\/p>\n<pre>type PersonType = {\n  name: string;\n  age: number;\n\n  private _privateProperty: number;\n\n  greet(): void;\n}\n\nconst person: PersonType = {\n  name: \"John Doe\",\n  age: 30,\n\n  greet() {\n    \/\/ ...\n  }\n}<\/pre>\n<p> \u767b\u5f55\u540e\u590d\u5236 <\/p>\n<h3>\u7ed3\u8bba<\/h3>\n<p>\u7c7b\u63a5\u53e3\u548c\u7c7b\u578b\u662f TypeScript \u4e2d\u5b9a\u4e49\u7c7b\u7684\u91cd\u8981\u5de5\u5177\u3002\u9009\u62e9\u54ea\u79cd\u673a\u5236\u53d6\u51b3\u4e8e\u5177\u4f53\u9700\u6c42\uff1a<\/p>\n<ul>\n<li> <strong>\u7c7b\u63a5\u53e3<\/strong>\u9002\u5408\u5b9a\u4e49\u7c7b\u7684\u516c\u5171\u9762\u5411\uff0c\u800c<strong>\u7c7b\u578b<\/strong>\u9002\u5408\u5b9a\u4e49\u7c7b\u7684\u5b8c\u6574\u7ed3\u6784\u548c\u884c\u4e3a\u3002<\/li>\n<\/ul>\n<p>\u4ee5\u4e0a\u5c31\u662f\u7c7b\u63a5\u53e3\u4e0e\u7c7b\u578b\u6709\u54ea\u4e9b\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>\u7c7b\u63a5\u53e3\u548c\u7c7b\u578b\u662f typescript \u4e2d\u5b9a\u4e49\u7c7b\u7ed3\u6784\u548c\u884c\u4e3a\u7684\u4e24\u79cd\u673a\u5236\u3002\u7c7b\u63a5\u53e3\u7528\u4e8e\u5b9a\u4e49\u7c7b\u7684\u516c\u5171 api\uff0c\u800c\u7c7b\u578b\u7528\u4e8e\u5b9a\u4e49\u7c7b\u7684\u5b8c\u6574\u7ed3\u6784\uff0c\u5305\u62ec\u79c1\u6709\u5b9e\u73b0\u7ec6\u8282\u3002\u4e3b\u8981\u533a\u522b\u5728\u4e8e\u8bbf\u95ee\u6027\uff08\u63a5\u53e3\u4ec5\u516c\u5f00\u7c7b\u6210\u5458\uff0c\u800c\u7c7b\u578b\u516c\u5f00\u5168\u90e8\u6210\u5458\uff09\u3001\u7ee7\u627f\uff08\u63a5\u53e3\u652f\u6301\u591a\u91cd\u7ee7\u627f\uff0c\u800c\u7c7b\u578b\u4ec5\u652f\u6301\u5355\u4e00\u7ee7\u627f\uff09\u548c\u5b9e\u4f8b\u5316\uff08\u63a5\u53e3\u4e0d\u80fd\u76f4\u63a5\u5b9e\u4f8b\u5316\uff0c\u800c\u7c7b\u578b\u53ef\u4ee5\uff09\u3002\u6839\u636e\u9700\u6c42\uff0c\u7c7b\u63a5\u53e3\u9002\u7528\u4e8e\u5b9a\u4e49\u7c7b\u7684\u516c\u5171\u9762\u5411\uff0c\u800c\u7c7b\u578b\u9002\u7528\u4e8e\u5b9a\u4e49\u7c7b\u7684\u5b8c\u6574\u7ed3\u6784\u548c\u884c\u4e3a\u3002 TypeScript \u7c7b\u63a5\u53e3\u4e0e\u7c7b\u578b TypeScript \u63d0\u4f9b\u4e86\u7c7b\u63a5\u53e3\u548c\u7c7b\u578b\u4e24\u79cd\u673a\u5236\u6765\u5b9a\u4e49\u7c7b\u7684\u5f62\u72b6\u548c\u884c\u4e3a\u3002\u867d\u7136\u5b83\u4eec\u6709\u76f8\u4f3c\u4e4b\u5904\uff0c\u4f46\u5b83\u4eec\u5728\u76ee\u7684\u548c\u4f7f\u7528\u65b9\u5f0f\u4e0a\u5b58\u5728\u5173\u952e\u5dee\u5f02\u3002 \u7c7b\u63a5\u53e3 \u76ee\u7684\uff1a\u5b9a\u4e49\u7c7b\u7684\u516c\u5171 API\uff0c\u5305\u62ec\u5176\u5c5e\u6027\u3001\u65b9\u6cd5\u548c\u4e8b\u4ef6\u3002 \u8bed\u6cd5\uff1a interface InterfaceName { \/\/ \u5c5e\u6027 property1: type1; property2: type2; \/\/ \u65b9\u6cd5 method1(arg1: type3, arg2: type4): returnType; method2(): void; \/\/ \u4e8b\u4ef6 event1: string; } \u767b\u5f55\u540e\u590d\u5236 \u7c7b\u578b \u76ee\u7684\uff1a\u5b9a\u4e49\u7c7b\u7684\u5b8c\u6574\u7ed3\u6784\uff0c\u5305\u62ec\u5176\u79c1\u6709\u5b9e\u73b0\u7ec6\u8282\u3002 \u8bed\u6cd5\uff1a type TypeName = { \/\/ \u5c5e\u6027 property1: type1; property2: type2; \/\/ \u65b9\u6cd5 method1(arg1: type3, arg2: type4): [&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-3097","post","type-post","status-publish","format-standard","hentry","category-16"],"_links":{"self":[{"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/posts\/3097","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=3097"}],"version-history":[{"count":0,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/posts\/3097\/revisions"}],"wp:attachment":[{"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/media?parent=3097"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/categories?post=3097"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/tags?post=3097"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}