{"id":3123,"date":"2024-11-10T09:35:12","date_gmt":"2024-11-10T01:35:12","guid":{"rendered":"https:\/\/fwq.ai\/blog\/3123\/"},"modified":"2024-11-10T09:35:12","modified_gmt":"2024-11-10T01:35:12","slug":"typescript%e5%85%a5%e9%97%a8%e5%9f%ba%e7%a1%80%e7%9f%a5%e8%af%86%e5%88%86%e4%ba%ab","status":"publish","type":"post","link":"https:\/\/fwq.ai\/blog\/3123\/","title":{"rendered":"typescript\u5165\u95e8\u57fa\u7840\u77e5\u8bc6\u5206\u4eab"},"content":{"rendered":"<blockquote><p>\n  typescript \u662f\u4e00\u79cd\u57fa\u4e8e javascript \u7684\u5f3a\u7c7b\u578b\u7f16\u7a0b\u8bed\u8a00\uff0c\u6269\u5c55\u4e86\u5176\u529f\u80fd\uff0c\u5f15\u5165\u4e86\u7c7b\u578b\u7cfb\u7edf\u3001\u63a5\u53e3\u548c\u7c7b\uff0c\u4ece\u800c\u589e\u5f3a\u4e86\u53ef\u8bfb\u6027\u3001\u53ef\u7ef4\u62a4\u6027\u548c\u53ef\u6269\u5c55\u6027\u3002\u5165\u95e8\u57fa\u7840\u77e5\u8bc6\u5305\u62ec\uff1a1. \u7c7b\u578b\u7cfb\u7edf\u5f3a\u5236\u6307\u5b9a\u53d8\u91cf\u7c7b\u578b\uff0c2. \u63a5\u53e3\u5b9a\u4e49\u5bf9\u8c61\u5951\u7ea6\uff0c3. \u7c7b\u652f\u6301\u9762\u5411\u5bf9\u8c61\u7f16\u7a0b\uff0c4. \u6a21\u5757\u7ec4\u7ec7\u4ee3\u7801\u3002\u4f7f\u7528 typescript \u6709\u52a9\u4e8e\u63d0\u9ad8\u4ee3\u7801\u8d28\u91cf\u3001\u589e\u5f3a\u53ef\u8bfb\u6027\u3001\u4fc3\u8fdb\u6a21\u5757\u5316\uff0c\u5e76\u4e14\u5b83\u517c\u5bb9 javascript\u3002\n<\/p><\/blockquote>\n<p><img decoding=\"async\" src=\"https:\/\/img.php.cn\/upload\/article\/202411\/08\/2024110803094431698.jpg\" class=\"aligncenter\" title=\"typescript\u5165\u95e8\u57fa\u7840\u77e5\u8bc6\u5206\u4eab\u63d2\u56fe\" alt=\"typescript\u5165\u95e8\u57fa\u7840\u77e5\u8bc6\u5206\u4eab\u63d2\u56fe\" \/><\/p>\n<p><strong>TypeScript \u5165\u95e8\u57fa\u7840<\/strong><\/p>\n<p>TypeScript \u662f\u4e00\u79cd\u57fa\u4e8e JavaScript \u7684\u5f3a\u7c7b\u578b\u7f16\u7a0b\u8bed\u8a00\uff0c\u7531\u5fae\u8f6f\u5f00\u53d1\u3002\u5b83\u6269\u5c55\u4e86 JavaScript \u7684\u529f\u80fd\uff0c\u5f15\u5165\u4e86\u7c7b\u578b\u7cfb\u7edf\u3001\u63a5\u53e3\u548c\u7c7b\uff0c\u6539\u5584\u4e86 JavaScript \u7684\u53ef\u8bfb\u6027\u3001\u53ef\u7ef4\u62a4\u6027\u548c\u53ef\u6269\u5c55\u6027\u3002<\/p>\n<p><strong>\u5165\u95e8\u57fa\u7840\u77e5\u8bc6\uff1a<\/strong><\/p>\n<p><strong>1. \u7c7b\u578b\u7cfb\u7edf<\/strong><\/p>\n<p>TypeScript \u5f15\u5165\u4e86\u5f3a\u7c7b\u578b\u7cfb\u7edf\uff0c\u8fd9\u610f\u5473\u7740\u53d8\u91cf\u5fc5\u987b\u6307\u5b9a\u5176\u9884\u671f\u7c7b\u578b\uff0c\u4f8b\u5982\u6570\u5b57\u3001\u5b57\u7b26\u4e32\u6216\u5e03\u5c14\u503c\u3002\u8fd9\u6709\u52a9\u4e8e\u5728\u7f16\u8bd1\u65f6\u68c0\u6d4b\u7c7b\u578b\u9519\u8bef\uff0c\u907f\u514d\u8fd0\u884c\u65f6\u9519\u8bef\u3002<\/p>\n<p><strong>2. \u63a5\u53e3<\/strong><\/p>\n<p>\u63a5\u53e3\u5b9a\u4e49\u4e86\u5bf9\u8c61\u7684\u5951\u7ea6\uff0c\u5b83\u6307\u5b9a\u4e86\u5bf9\u8c61\u5fc5\u987b\u5177\u6709\u7684\u5c5e\u6027\u548c\u65b9\u6cd5\u3002\u63a5\u53e3\u4f7f\u4ee3\u7801\u66f4\u6613\u4e8e\u9605\u8bfb\u548c\u7406\u89e3\uff0c\u5e76\u5f3a\u5236\u6267\u884c\u4ee3\u7801\u4e00\u81f4\u6027\u3002<\/p>\n<p><strong>3. \u7c7b<\/strong><\/p>\n<p>TypeScript \u652f\u6301\u9762\u5411\u5bf9\u8c61\u7f16\u7a0b\uff0c\u5141\u8bb8\u521b\u5efa\u7c7b\u548c\u5b9e\u4f8b\u5316\u5bf9\u8c61\u3002\u7c7b\u4f7f\u4ee3\u7801\u66f4\u6613\u4e8e\u7ec4\u7ec7\u548c\u7ef4\u62a4\uff0c\u5e76\u4fc3\u8fdb\u4ee3\u7801\u91cd\u7528\u3002<\/p>\n<p><strong>4. \u6a21\u5757<\/strong><\/p>\n<p>TypeScript \u4f7f\u7528\u6a21\u5757\u7ec4\u7ec7\u4ee3\u7801\uff0c\u5141\u8bb8\u5c06\u4ee3\u7801\u5206\u6210\u8f83\u5c0f\u7684\u3001\u53ef\u91cd\u7528\u7684\u90e8\u5206\u3002\u6a21\u5757\u53ef\u4ee5\u5bfc\u51fa\u548c\u5bfc\u5165\uff0c\u4fc3\u8fdb\u4ee3\u7801\u6a21\u5757\u5316\u3002<\/p>\n<p><strong>\u5165\u95e8\u6b65\u9aa4\uff1a<\/strong><\/p>\n<ul>\n<li> <strong>\u5b89\u88c5 TypeScript\uff1a<\/strong> \u4f7f\u7528 npm \u6216 yarn \u5b89\u88c5 TypeScript\u3002<\/li>\n<li> <strong>\u521b\u5efa TypeScript \u6587\u4ef6\uff1a<\/strong> \u521b\u5efa\u4e00\u4e2a\u5e26\u6709 .ts \u6269\u5c55\u540d\u7684\u6587\u4ef6\uff0c\u4f8b\u5982 hello.ts\u3002<\/li>\n<li> <strong>\u58f0\u660e\u7c7b\u578b\uff1a<\/strong> \u6307\u5b9a\u53d8\u91cf\u548c\u53c2\u6570\u7684\u7c7b\u578b\uff0c\u4f8b\u5982\uff1a<\/li>\n<\/ul>\n<pre>let name: string = \"TypeScript\";<\/pre>\n<p> \u767b\u5f55\u540e\u590d\u5236 <\/p>\n<ul>\n<li> <strong>\u4f7f\u7528\u63a5\u53e3\uff1a<\/strong> \u5b9a\u4e49\u63a5\u53e3\u5e76\u4f7f\u7528\u5b83\u7ea6\u675f\u5bf9\u8c61\uff0c\u4f8b\u5982\uff1a<\/li>\n<\/ul>\n<pre>interface Person {\n  name: string;\n  age: number;\n}<\/pre>\n<p> \u767b\u5f55\u540e\u590d\u5236 <\/p>\n<ul>\n<li> <strong>\u521b\u5efa\u7c7b\uff1a<\/strong> \u4f7f\u7528 class \u5173\u952e\u5b57\u521b\u5efa\u7c7b\uff0c\u4f8b\u5982\uff1a<\/li>\n<\/ul>\n<pre>class MyClass {\n  \/\/ \u4ee3\u7801...\n}<\/pre>\n<p> \u767b\u5f55\u540e\u590d\u5236 <\/p>\n<p><strong>\u4f18\u70b9\uff1a<\/strong><\/p>\n<ul>\n<li>\u63d0\u9ad8\u4ee3\u7801\u8d28\u91cf\uff1a\u5f3a\u7c7b\u578b\u7cfb\u7edf\u548c\u63a5\u53e3\u5f3a\u5236\u6267\u884c\u4ee3\u7801\u4e00\u81f4\u6027\u548c\u51cf\u5c11\u9519\u8bef\u3002<\/li>\n<li>\u589e\u5f3a\uff1a\u7c7b\u578b\u6ce8\u91ca\u4f7f\u4ee3\u7801\u66f4\u5bb9\u6613\u9605\u8bfb\u548c\u7406\u89e3\u3002<\/li>\n<li>\u4fc3\u8fdb\u6a21\u5757\u5316\uff1a\u6a21\u5757\u5141\u8bb8\u5c06\u4ee3\u7801\u5206\u89e3\u4e3a\u8f83\u5c0f\u7684\u3001\u53ef\u91cd\u7528\u7684\u90e8\u5206\u3002<\/li>\n<li>\u517c\u5bb9 JavaScript\uff1aTypeScript \u4ee3\u7801\u53ef\u4ee5\u7f16\u8bd1\u6210\u7eaf JavaScript\uff0c\u4f7f\u5176\u4e0e\u73b0\u6709 JavaScript \u4ee3\u7801\u5e93\u517c\u5bb9\u3002<\/li>\n<\/ul>\n<p>\u4ee5\u4e0a\u5c31\u662f\u5165\u95e8\u57fa\u7840\u77e5\u8bc6\u5206\u4eab\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 \u662f\u4e00\u79cd\u57fa\u4e8e javascript \u7684\u5f3a\u7c7b\u578b\u7f16\u7a0b\u8bed\u8a00\uff0c\u6269\u5c55\u4e86\u5176\u529f\u80fd\uff0c\u5f15\u5165\u4e86\u7c7b\u578b\u7cfb\u7edf\u3001\u63a5\u53e3\u548c\u7c7b\uff0c\u4ece\u800c\u589e\u5f3a\u4e86\u53ef\u8bfb\u6027\u3001\u53ef\u7ef4\u62a4\u6027\u548c\u53ef\u6269\u5c55\u6027\u3002\u5165\u95e8\u57fa\u7840\u77e5\u8bc6\u5305\u62ec\uff1a1. \u7c7b\u578b\u7cfb\u7edf\u5f3a\u5236\u6307\u5b9a\u53d8\u91cf\u7c7b\u578b\uff0c2. \u63a5\u53e3\u5b9a\u4e49\u5bf9\u8c61\u5951\u7ea6\uff0c3. \u7c7b\u652f\u6301\u9762\u5411\u5bf9\u8c61\u7f16\u7a0b\uff0c4. \u6a21\u5757\u7ec4\u7ec7\u4ee3\u7801\u3002\u4f7f\u7528 typescript \u6709\u52a9\u4e8e\u63d0\u9ad8\u4ee3\u7801\u8d28\u91cf\u3001\u589e\u5f3a\u53ef\u8bfb\u6027\u3001\u4fc3\u8fdb\u6a21\u5757\u5316\uff0c\u5e76\u4e14\u5b83\u517c\u5bb9 javascript\u3002 TypeScript \u5165\u95e8\u57fa\u7840 TypeScript \u662f\u4e00\u79cd\u57fa\u4e8e JavaScript \u7684\u5f3a\u7c7b\u578b\u7f16\u7a0b\u8bed\u8a00\uff0c\u7531\u5fae\u8f6f\u5f00\u53d1\u3002\u5b83\u6269\u5c55\u4e86 JavaScript \u7684\u529f\u80fd\uff0c\u5f15\u5165\u4e86\u7c7b\u578b\u7cfb\u7edf\u3001\u63a5\u53e3\u548c\u7c7b\uff0c\u6539\u5584\u4e86 JavaScript \u7684\u53ef\u8bfb\u6027\u3001\u53ef\u7ef4\u62a4\u6027\u548c\u53ef\u6269\u5c55\u6027\u3002 \u5165\u95e8\u57fa\u7840\u77e5\u8bc6\uff1a 1. \u7c7b\u578b\u7cfb\u7edf TypeScript \u5f15\u5165\u4e86\u5f3a\u7c7b\u578b\u7cfb\u7edf\uff0c\u8fd9\u610f\u5473\u7740\u53d8\u91cf\u5fc5\u987b\u6307\u5b9a\u5176\u9884\u671f\u7c7b\u578b\uff0c\u4f8b\u5982\u6570\u5b57\u3001\u5b57\u7b26\u4e32\u6216\u5e03\u5c14\u503c\u3002\u8fd9\u6709\u52a9\u4e8e\u5728\u7f16\u8bd1\u65f6\u68c0\u6d4b\u7c7b\u578b\u9519\u8bef\uff0c\u907f\u514d\u8fd0\u884c\u65f6\u9519\u8bef\u3002 2. \u63a5\u53e3 \u63a5\u53e3\u5b9a\u4e49\u4e86\u5bf9\u8c61\u7684\u5951\u7ea6\uff0c\u5b83\u6307\u5b9a\u4e86\u5bf9\u8c61\u5fc5\u987b\u5177\u6709\u7684\u5c5e\u6027\u548c\u65b9\u6cd5\u3002\u63a5\u53e3\u4f7f\u4ee3\u7801\u66f4\u6613\u4e8e\u9605\u8bfb\u548c\u7406\u89e3\uff0c\u5e76\u5f3a\u5236\u6267\u884c\u4ee3\u7801\u4e00\u81f4\u6027\u3002 3. \u7c7b TypeScript \u652f\u6301\u9762\u5411\u5bf9\u8c61\u7f16\u7a0b\uff0c\u5141\u8bb8\u521b\u5efa\u7c7b\u548c\u5b9e\u4f8b\u5316\u5bf9\u8c61\u3002\u7c7b\u4f7f\u4ee3\u7801\u66f4\u6613\u4e8e\u7ec4\u7ec7\u548c\u7ef4\u62a4\uff0c\u5e76\u4fc3\u8fdb\u4ee3\u7801\u91cd\u7528\u3002 4. \u6a21\u5757 TypeScript \u4f7f\u7528\u6a21\u5757\u7ec4\u7ec7\u4ee3\u7801\uff0c\u5141\u8bb8\u5c06\u4ee3\u7801\u5206\u6210\u8f83\u5c0f\u7684\u3001\u53ef\u91cd\u7528\u7684\u90e8\u5206\u3002\u6a21\u5757\u53ef\u4ee5\u5bfc\u51fa\u548c\u5bfc\u5165\uff0c\u4fc3\u8fdb\u4ee3\u7801\u6a21\u5757\u5316\u3002 \u5165\u95e8\u6b65\u9aa4\uff1a \u5b89\u88c5 TypeScript\uff1a \u4f7f\u7528 npm \u6216 yarn \u5b89\u88c5 TypeScript\u3002 \u521b\u5efa TypeScript \u6587\u4ef6\uff1a \u521b\u5efa\u4e00\u4e2a\u5e26\u6709 .ts \u6269\u5c55\u540d\u7684\u6587\u4ef6\uff0c\u4f8b\u5982 hello.ts\u3002 \u58f0\u660e\u7c7b\u578b\uff1a \u6307\u5b9a\u53d8\u91cf\u548c\u53c2\u6570\u7684\u7c7b\u578b\uff0c\u4f8b\u5982\uff1a [&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-3123","post","type-post","status-publish","format-standard","hentry","category-16"],"_links":{"self":[{"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/posts\/3123","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=3123"}],"version-history":[{"count":0,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/posts\/3123\/revisions"}],"wp:attachment":[{"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/media?parent=3123"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/categories?post=3123"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/tags?post=3123"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}