{"id":3110,"date":"2024-11-10T12:51:42","date_gmt":"2024-11-10T04:51:42","guid":{"rendered":"https:\/\/fwq.ai\/blog\/3110\/"},"modified":"2024-11-10T12:51:42","modified_gmt":"2024-11-10T04:51:42","slug":"typescript%e7%8e%af%e5%a2%83%e9%85%8d%e7%bd%ae%e6%95%99%e7%a8%8b","status":"publish","type":"post","link":"https:\/\/fwq.ai\/blog\/3110\/","title":{"rendered":"typescript\u73af\u5883\u914d\u7f6e\u6559\u7a0b"},"content":{"rendered":"<blockquote><p>\n  typescript \u73af\u5883\u914d\u7f6e\u6982\u8ff0\uff1a\u5b89\u88c5 node.js\u5b89\u88c5 typescript\u521b\u5efa typescript \u9879\u76ee\u7f16\u8bd1 typescript \u4ee3\u7801\u914d\u7f6e ide\uff08\u53ef\u9009\uff09\n<\/p><\/blockquote>\n<p><img decoding=\"async\" src=\"https:\/\/img.php.cn\/upload\/article\/202411\/08\/2024110801311217599.jpg\" class=\"aligncenter\" title=\"typescript\u73af\u5883\u914d\u7f6e\u6559\u7a0b\u63d2\u56fe\" alt=\"typescript\u73af\u5883\u914d\u7f6e\u6559\u7a0b\u63d2\u56fe\" \/><\/p>\n<p><strong>TypeScript \u73af\u5883\u914d\u7f6e\u6559\u7a0b<\/strong><\/p>\n<p><strong>\u6982\u8ff0<\/strong><\/p>\n<p>TypeScript \u662f\u4e00\u79cd\u5efa\u7acb\u5728 JavaScript \u4e4b\u4e0a\u7684\u5f3a\u7c7b\u578b\u8bed\u8a00\uff0c\u53ef\u5e2e\u52a9\u5f00\u53d1\u4eba\u5458\u7f16\u5199\u5065\u58ee\u4e14\u53ef\u7ef4\u62a4\u7684\u4ee3\u7801\u3002\u4e3a\u4e86\u5728\u672c\u5730\u73af\u5883\u4e2d\u4f7f\u7528 TypeScript\uff0c\u9700\u8981\u8fdb\u884c\u73af\u5883\u914d\u7f6e\u3002<\/p>\n<p><strong>\u6b65\u9aa4 1\uff1a\u5b89\u88c5 Node.js<\/strong><\/p>\n<ul>\n<li>\u524d\u5f80 Node.js \u5b98\u7f51\uff08https:\/\/.org\/en\/\uff09\uff0c\u4e0b\u8f7d\u5e76\u5b89\u88c5\u4e0e\u60a8\u7684\u517c\u5bb9\u7684\u7248\u672c\u3002<\/li>\n<\/ul>\n<p><strong>\u6b65\u9aa4 2\uff1a\u5b89\u88c5 TypeScript<\/strong><\/p>\n<ul>\n<li>\u6253\u5f00\u7ec8\u7aef\u6216\u547d\u4ee4\u63d0\u793a\u7b26\uff0c\u5e76\u4f7f\u7528\u4ee5\u4e0b\u547d\u4ee4\u5b89\u88c5 TypeScript\uff1a<\/li>\n<\/ul>\n<pre>npm install -g typescript<\/pre>\n<p> \u767b\u5f55\u540e\u590d\u5236 <\/p>\n<ul>\n<li>\u6b64\u547d\u4ee4\u5c06\u5728\u5168\u5c40\u8303\u56f4\u5185\u5b89\u88c5 TypeScript\u3002<\/li>\n<\/ul>\n<p><strong>\u6b65\u9aa4 3\uff1a\u521b\u5efa TypeScript \u9879\u76ee<\/strong><\/p>\n<ul>\n<li>\u521b\u5efa\u4e00\u4e2a\u65b0\u7684\u6587\u4ef6\u5939\u4f5c\u4e3a\u9879\u76ee\u76ee\u5f55\u3002<\/li>\n<li>\u5728\u8be5\u6587\u4ef6\u5939\u4e2d\uff0c\u521b\u5efa\u4e00\u4e2a\u5e26\u6709 .ts \u6269\u5c55\u540d\u7684 TypeScript \u6e90\u6587\u4ef6\uff0c\u4f8b\u5982 mn.ts\u3002<\/li>\n<\/ul>\n<p><strong>\u6b65\u9aa4 4\uff1a\u7f16\u8bd1 TypeScript<\/strong><\/p>\n<ul>\n<li>\u8981\u7f16\u8bd1 TypeScript \u4ee3\u7801\uff0c\u8bf7\u4f7f\u7528 tsc \u547d\u4ee4\uff0c\u540e\u8ddf\u8981\u7f16\u8bd1\u7684\u6587\u4ef6\uff1a<\/li>\n<\/ul>\n<pre>tsc main.ts<\/pre>\n<p> \u767b\u5f55\u540e\u590d\u5236 <\/p>\n<ul>\n<li>\u6b64\u547d\u4ee4\u5c06\u5728 main.js \u6587\u4ef6\u4e2d\u751f\u6210\u5df2\u7f16\u8bd1\u7684 JavaScript \u8f93\u51fa\u3002<\/li>\n<\/ul>\n<p><strong>\u6b65\u9aa4 5\uff1a\u914d\u7f6e IDE\uff08\u53ef\u9009\uff09<\/strong><\/p>\n<ul>\n<li>\u5bf9\u4e8e\u66f4\u597d\u7684\u5f00\u53d1\u4f53\u9a8c\uff0c\u53ef\u4ee5\u5728 IDE \u4e2d\u914d\u7f6e TypeScript\u3002<\/li>\n<li>\u5927\u591a\u6570\u6d41\u884c\u7684 IDE\uff08\u4f8b\u5982 Visual Studio Code\u3001WebStorm\uff09\u90fd\u652f\u6301 TypeScript\uff0c\u5e76\u63d0\u4f9b\u4ee3\u7801\u9ad8\u4eae\u3001\u81ea\u52a8\u8865\u5168\u7b49\u529f\u80fd\u3002<\/li>\n<\/ul>\n<p><strong>\u9a8c\u8bc1<\/strong><\/p>\n<ul>\n<li>\u4e3a\u4e86\u9a8c\u8bc1\u5b89\u88c5\u662f\u5426\u6210\u529f\uff0c\u53ef\u4ee5\u8fd0\u884c\u4ee5\u4e0b\u547d\u4ee4\uff1a<\/li>\n<\/ul>\n<pre>tsc --version<\/pre>\n<p> \u767b\u5f55\u540e\u590d\u5236 <\/p>\n<ul>\n<li>\u5982\u679c\u5df2\u6b63\u786e\u5b89\u88c5\uff0c\u6b64\u547d\u4ee4\u5e94\u663e\u793a TypeScript \u7248\u672c\u3002<\/li>\n<\/ul>\n<p><strong>\u5176\u4ed6\u63d0\u793a<\/strong><\/p>\n<ul>\n<li>\u53ef\u4ee5\u901a\u8fc7\u521b\u5efa tsconfig.json \u6587\u4ef6\u6765\u914d\u7f6e TypeScript \u7f16\u8bd1\u5668\u9009\u9879\u3002<\/li>\n<li>\u4f7f\u7528 &#8211;watch \u9009\u9879\u76d1\u89c6\u6587\u4ef6\u66f4\u6539\u5e76\u81ea\u52a8\u7f16\u8bd1\u4ee3\u7801\u3002<\/li>\n<li>TypeScript \u63d0\u4f9b\u4e86\u5404\u79cd\u547d\u4ee4\u884c\u5b9e\u7528\u7a0b\u5e8f\uff0c\u4f8b\u5982 tsc \u548c tsserver\uff0c\u7528\u4e8e\u4e0d\u540c\u7684\u76ee\u7684\u3002<\/li>\n<\/ul>\n<p>\u4ee5\u4e0a\u5c31\u662f\u73af\u5883\u914d\u7f6e\u6559\u7a0b\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 \u73af\u5883\u914d\u7f6e\u6982\u8ff0\uff1a\u5b89\u88c5 node.js\u5b89\u88c5 typescript\u521b\u5efa typescript \u9879\u76ee\u7f16\u8bd1 typescript \u4ee3\u7801\u914d\u7f6e ide\uff08\u53ef\u9009\uff09 TypeScript \u73af\u5883\u914d\u7f6e\u6559\u7a0b \u6982\u8ff0 TypeScript \u662f\u4e00\u79cd\u5efa\u7acb\u5728 JavaScript \u4e4b\u4e0a\u7684\u5f3a\u7c7b\u578b\u8bed\u8a00\uff0c\u53ef\u5e2e\u52a9\u5f00\u53d1\u4eba\u5458\u7f16\u5199\u5065\u58ee\u4e14\u53ef\u7ef4\u62a4\u7684\u4ee3\u7801\u3002\u4e3a\u4e86\u5728\u672c\u5730\u73af\u5883\u4e2d\u4f7f\u7528 TypeScript\uff0c\u9700\u8981\u8fdb\u884c\u73af\u5883\u914d\u7f6e\u3002 \u6b65\u9aa4 1\uff1a\u5b89\u88c5 Node.js \u524d\u5f80 Node.js \u5b98\u7f51\uff08https:\/\/.org\/en\/\uff09\uff0c\u4e0b\u8f7d\u5e76\u5b89\u88c5\u4e0e\u60a8\u7684\u517c\u5bb9\u7684\u7248\u672c\u3002 \u6b65\u9aa4 2\uff1a\u5b89\u88c5 TypeScript \u6253\u5f00\u7ec8\u7aef\u6216\u547d\u4ee4\u63d0\u793a\u7b26\uff0c\u5e76\u4f7f\u7528\u4ee5\u4e0b\u547d\u4ee4\u5b89\u88c5 TypeScript\uff1a npm install -g typescript \u767b\u5f55\u540e\u590d\u5236 \u6b64\u547d\u4ee4\u5c06\u5728\u5168\u5c40\u8303\u56f4\u5185\u5b89\u88c5 TypeScript\u3002 \u6b65\u9aa4 3\uff1a\u521b\u5efa TypeScript \u9879\u76ee \u521b\u5efa\u4e00\u4e2a\u65b0\u7684\u6587\u4ef6\u5939\u4f5c\u4e3a\u9879\u76ee\u76ee\u5f55\u3002 \u5728\u8be5\u6587\u4ef6\u5939\u4e2d\uff0c\u521b\u5efa\u4e00\u4e2a\u5e26\u6709 .ts \u6269\u5c55\u540d\u7684 TypeScript \u6e90\u6587\u4ef6\uff0c\u4f8b\u5982 mn.ts\u3002 \u6b65\u9aa4 4\uff1a\u7f16\u8bd1 TypeScript \u8981\u7f16\u8bd1 TypeScript \u4ee3\u7801\uff0c\u8bf7\u4f7f\u7528 tsc \u547d\u4ee4\uff0c\u540e\u8ddf\u8981\u7f16\u8bd1\u7684\u6587\u4ef6\uff1a tsc [&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-3110","post","type-post","status-publish","format-standard","hentry","category-16"],"_links":{"self":[{"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/posts\/3110","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=3110"}],"version-history":[{"count":0,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/posts\/3110\/revisions"}],"wp:attachment":[{"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/media?parent=3110"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/categories?post=3110"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/tags?post=3110"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}