{"id":10392,"date":"2023-03-31T20:40:20","date_gmt":"2023-03-31T12:40:20","guid":{"rendered":"http:\/\/123.57.164.21\/?p=10392"},"modified":"2023-03-31T20:40:20","modified_gmt":"2023-03-31T12:40:20","slug":"typescript-%e4%bb%8b%e7%bb%8d","status":"publish","type":"post","link":"https:\/\/92it.top\/?p=10392","title":{"rendered":"TypeScript \u4ecb\u7ecd"},"content":{"rendered":"\n<p>\u968f\u7740\u524d\u7aef\u5de5\u7a0b\u5316\u7684\u5feb\u901f\u53d1\u5c55\uff0c TypeScript \u53d8\u5f97\u8d8a\u6765\u8d8a\u53d7\u6b22\u8fce\uff0c\u5b83\u5df2\u7ecf\u6210\u4e3a\u524d\u7aef\u5f00\u53d1\u4eba\u5458\u5fc5\u5907\u6280\u80fd\u3002 TypeScript \u6700\u521d\u662f\u7531\u5fae\u8f6f\u5f00\u53d1\u5e76\u5f00\u6e90\u7684\u4e00\u79cd\u7f16\u7a0b\u8bed\u8a00\uff0c\u81ea2012\u5e7410\u6708\u53d1\u5e03\u9996\u4e2a\u516c\u5f00\u7248\u672c\u4ee5\u6765\uff0c\u5b83\u5df2\u5f97\u5230\u4e86\u4eba\u4eec\u7684\u5e7f\u6cdb\u8ba4\u53ef\u3002TypeScript \u53d1\u5c55\u81f3\u4eca\uff0c\u5df2\u7ecf\u6210\u4e3a\u5f88\u591a\u5927\u578b\u9879\u76ee\u7684\u6807\u914d\uff0c\u5176\u63d0\u4f9b\u7684\u9759\u6001\u7c7b\u578b\u7cfb\u7edf\uff0c\u5927\u5927\u589e\u5f3a\u4e86\u4ee3\u7801\u7684\u53ef\u8bfb\u6027\u3001\u53ef\u7ef4\u62a4\u6027\u548c\u4ee3\u7801\u8d28\u91cf\u3002\u540c\u65f6\uff0c\u5b83\u63d0\u4f9b\u6700\u65b0\u7684JavaScript\u7279\u6027\uff0c\u80fd\u8ba9\u6211\u4eec\u6784\u5efa\u66f4\u52a0\u5065\u58ee\u7684\u7ec4\u4ef6\uff0c\u65b0\u7248\u672c\u4e0d\u65ad\u8fed\u4ee3\u66f4\u65b0\uff0c\u7f16\u5199\u524d\u7aef\u4ee3\u7801\u4e5f\u8d8a\u6765\u8d8a\u9999\u3002<\/p>\n\n\n\n<div class=\"wp-block-image\"><figure class=\"aligncenter size-large is-resized\"><img loading=\"lazy\" decoding=\"async\" src=\"http:\/\/123.57.164.21\/wp-content\/uploads\/2023\/03\/image-372-1024x411.png\" alt=\"\" class=\"wp-image-10393\" width=\"525\" height=\"211\" srcset=\"https:\/\/92it.top\/wp-content\/uploads\/2023\/03\/image-372-1024x411.png 1024w, https:\/\/92it.top\/wp-content\/uploads\/2023\/03\/image-372-300x120.png 300w, https:\/\/92it.top\/wp-content\/uploads\/2023\/03\/image-372-768x308.png 768w, https:\/\/92it.top\/wp-content\/uploads\/2023\/03\/image-372-830x333.png 830w, https:\/\/92it.top\/wp-content\/uploads\/2023\/03\/image-372-230x92.png 230w, https:\/\/92it.top\/wp-content\/uploads\/2023\/03\/image-372-350x141.png 350w, https:\/\/92it.top\/wp-content\/uploads\/2023\/03\/image-372-480x193.png 480w, https:\/\/92it.top\/wp-content\/uploads\/2023\/03\/image-372.png 1340w\" sizes=\"(max-width: 525px) 100vw, 525px\" \/><\/figure><\/div>\n\n\n\n<p><strong>1 \u4e3a\u4ec0\u4e48\u4f7f\u7528 TypeScript<\/strong><\/p>\n\n\n\n<hr class=\"wp-block-separator\"\/>\n\n\n\n<p>\u5fae\u8f6f\u63d0\u51fa TypeScript \u4e3b\u8981\u662f\u4e3a\u4e86\u5b9e\u73b0\u4e24\u4e2a\u76ee\u6807\uff1a\u4e3a JavaScript \u63d0\u4f9b\u53ef\u9009\u7684\u7c7b\u578b\u7cfb\u7edf\uff0c\u517c\u5bb9\u5f53\u524d\u53ca\u672a\u6765\u7684 JavaScript \u7279\u6027\u3002\u9996\u5148\u7c7b\u578b\u7cfb\u7edf\u80fd\u591f\u63d0\u9ad8\u4ee3\u7801\u7684\u8d28\u91cf\u548c\u53ef\u7ef4\u62a4\u6027\uff0c\u56fd\u5185\u5916\u5927\u578b\u56e2\u961f\u7ecf\u8fc7\u4e0d\u65ad\u5b9e\u8df5\u540e\u5f97\u51fa\u4e00\u4e9b\u7ed3\u8bba\uff1a<\/p>\n\n\n\n<ul><li>\u7c7b\u578b\u6709\u5229\u4e8e\u4ee3\u7801\u7684\u91cd\u6784\uff0c\u5b83\u6709\u5229\u4e8e\u7f16\u8bd1\u5668\u5728\u7f16\u8bd1\u65f6\u800c\u4e0d\u662f\u8fd0\u884c\u65f6\u53d1\u73b0\u9519\u8bef\uff1b<\/li><li>\u7c7b\u578b\u662f\u51fa\u8272\u7684\u6587\u6863\u5f62\u5f0f\u4e4b\u4e00\uff0c\u826f\u597d\u7684\u51fd\u6570\u58f0\u660e\u80dc\u8fc7\u5197\u957f\u7684\u4ee3\u7801\u6ce8\u91ca\uff0c\u901a\u8fc7\u58f0\u660e\u5373\u53ef\u77e5\u9053\u5177\u4f53\u7684\u5b9e\u73b0\uff1b<\/li><\/ul>\n\n\n\n<p>\u50cf\u5176\u4ed6\u8bed\u8a00\u90fd\u6709\u7c7b\u578b\u7684\u5b58\u5728\uff0c\u5982\u679c\u5f3a\u52a0\u4e8e JavaScript \u4e4b\u4e0a\uff0c\u7c7b\u578b\u53ef\u80fd\u4f1a\u6709\u4e00\u4e9b\u4e0d\u5fc5\u8981\u7684\u590d\u6742\u6027\uff0c\u800c TypeScript \u5728\u4e24\u8005\u4e4b\u95f4\u505a\u4e86\u6298\u4e2d\u5904\u7406\u5c3d\u53ef\u80fd\u5730\u964d\u4f4e\u4e86\u5165\u95e8\u95e8\u69db\uff0c\u5b83\u4f7f JavaScript \u5373 TypeScript \uff0c\u4e3a JavaScript \u63d0\u4f9b\u4e86\u7f16\u8bd1\u65f6\u7684\u7c7b\u578b\u5b89\u5168\u3002TypeScript \u7c7b\u578b\u5b8c\u5168\u662f\u53ef\u9009\u7684\uff0c\u539f\u6765\u7684 .js \u6587\u4ef6\u53ef\u4ee5\u76f4\u63a5\u88ab\u91cd\u547d\u540d\u4e3a .ts \uff0cts \u6587\u4ef6\u53ef\u4ee5\u88ab\u7f16\u8bd1\u6210\u6807\u51c6\u7684 JavaScript \u4ee3\u7801\uff0c\u5e76\u4fdd\u8bc1\u7f16\u8bd1\u540e\u7684\u4ee3\u7801\u5168\u90e8\u517c\u5bb9\uff0c\u5b83\u4e5f\u88ab\u6210\u4e3a JavaScript \u7684 \u201c\u8d85\u96c6\u201d\u3002\u6ca1\u6709\u7c7b\u578b\u7684 JavaScript \u8bed\u6cd5\u867d\u7136\u7b80\u5355\u7075\u6d3b\uff0c\u4f7f\u7528\u7684\u53d8\u91cf\u662f\u5f31\u7c7b\u578b\uff0c\u4f46\u662f\u6bd4\u8f83\u96be\u4ee5\u638c\u63e1\uff0cTypeScript \u63d0\u4f9b\u7684\u9759\u6001\u7c7b\u578b\u68c0\u67e5\uff0c\u5f88\u597d\u7684\u5f25\u8865\u4e86 JavaScript \u7684\u4e0d\u8db3\u3002<\/p>\n\n\n\n<p>TypeScript \u7c7b\u578b\u53ef\u4ee5\u662f\u9690\u5f0f\u7684\u4e5f\u53ef\u4ee5\u662f\u663e\u5f0f\u7684\uff0c\u5b83\u4f1a\u5c3d\u53ef\u80fd\u5b89\u5168\u5730\u63a8\u65ad\u7c7b\u578b\uff0c\u4ee5\u4fbf\u5728\u4ee3\u7801\u5f00\u53d1\u8fc7\u7a0b\u4e2d\u4ee5\u6781\u5c0f\u7684\u6210\u672c\u4e3a\u4f60\u63d0\u4f9b\u7c7b\u578b\u5b89\u5168\uff0c\u4e5f\u53ef\u4ee5\u4f7f\u7528\u663e\u5f0f\u7684\u58f0\u660e\u7c7b\u578b\u6ce8\u89e3\u8ba9\u7f16\u8bd1\u5668\u7f16\u8bd1\u51fa\u6211\u4eec\u60f3\u8981\u7684\u5185\u5bb9\uff0c\u66f4\u91cd\u8981\u7684\u662f\u4e3a\u4e0b\u4e00\u4e2a\u5fc5\u987b\u9605\u8bfb\u4ee3\u7801\u7684\u5f00\u53d1\u4eba\u5458\u7406\u89e3\u4ee3\u7801\u903b\u8f91\u3002<\/p>\n\n\n\n<p>\u7c7b\u578b\u9519\u8bef\u4e5f\u4e0d\u4f1a\u963b\u6b62JavaScript \u7684\u6b63\u5e38\u8fd0\u884c\uff0c\u4e3a\u4e86\u65b9\u4fbf\u628a JavaScript \u4ee3\u7801\u8fc1\u79fb\u5230 TypeScript\uff0c\u5373\u4f7f\u5b58\u5728\u7f16\u8bd1\u9519\u8bef\uff0cTypeScript \u4e5f\u4f1a\u88ab\u7f16\u8bd1\u51fa\u5b8c\u6574\u7684 JavaScript \u4ee3\u7801\uff0c\u8fd9\u4e0e\u5176\u4ed6\u8bed\u8a00\u7684\u7f16\u8bd1\u5668\u5de5\u4f5c\u65b9\u5f0f\u6709\u5f88\u5927\u4e0d\u540c\uff0c\u8fd9\u4e5f\u6b63\u662f TypeScript \u88ab\u9752\u7750\u7684\u53e6\u4e00\u4e2a\u539f\u56e0\u3002<\/p>\n\n\n\n<p><strong>TypeScript \u7684\u7279\u70b9\u8fd8\u6709\u5f88\u591a\u6bd4\u5982\u4e0b\u9762\u8fd9\u4e9b\uff1a<\/strong><\/p>\n\n\n\n<ul><li>\u514d\u8d39\u5f00\u6e90\uff0c\u4f7f\u7528 Apache \u6388\u6743\u534f\u8bae\uff1b<\/li><li>\u57fa\u4e8eECMAScript \u6807\u51c6\u8fdb\u884c\u62d3\u5c55\uff0c\u662f JavaScript \u7684\u8d85\u96c6\uff1b<\/li><li>\u6dfb\u52a0\u4e86\u53ef\u9009\u9759\u6001\u7c7b\u578b\u3001\u7c7b\u548c\u6a21\u5757\uff1b<\/li><li>\u53ef\u4ee5\u7f16\u8bd1\u4e3a\u53ef\u8bfb\u7684\u3001\u7b26\u5408ECMAScript \u89c4\u8303\u7684 JavaScript\uff1b<\/li><li>\u6210\u4e3a\u4e00\u6b3e\u8de8\u5e73\u53f0\u7684\u5de5\u5177\uff0c\u652f\u6301\u6240\u6709\u7684\u6d4f\u89c8\u5668\u3001\u4e3b\u673a\u548c\u64cd\u4f5c\u7cfb\u7edf\uff1b<\/li><li>\u4fdd\u8bc1\u53ef\u4ee5\u4e0e JavaScript \u4ee3\u7801\u4e00\u8d77\u4f7f\u7528\uff0c\u65e0\u987b\u4fee\u6539\uff08\u8fd9\u4e00\u70b9\u4fdd\u8bc1\u4e86 JavaScript \u9879\u76ee\u53ef\u4ee5\u5411 TypeScript \u5e73\u6ed1\u8fc1\u79fb\uff09\uff1b<\/li><li>\u6587\u4ef6\u6269\u5c55\u540d\u662f ts\/tsx\uff1b<\/li><li>\u7f16\u8bd1\u65f6\u68c0\u67e5\uff0c\u4e0d\u6c61\u67d3\u8fd0\u884c\u65f6\uff1b<\/li><\/ul>\n\n\n\n<p>\u603b\u7684\u6765\u8bf4\u6211\u4eec\u6ca1\u6709\u7406\u7531\u4e0d\u4f7f\u7528 TypeScript\uff0c \u56e0\u4e3a JavaScript \u5c31\u662f TypeScript\uff0cTypeScript \u53ef\u4ee5\u8ba9 JavaScript \u66f4\u7f8e\u597d\u3002<\/p>\n\n\n\n<div class=\"wp-block-image\"><figure class=\"aligncenter size-full is-resized\"><img loading=\"lazy\" decoding=\"async\" src=\"http:\/\/123.57.164.21\/wp-content\/uploads\/2023\/03\/image-373.png\" alt=\"\" class=\"wp-image-10394\" width=\"319\" height=\"311\" srcset=\"https:\/\/92it.top\/wp-content\/uploads\/2023\/03\/image-373.png 914w, https:\/\/92it.top\/wp-content\/uploads\/2023\/03\/image-373-300x293.png 300w, https:\/\/92it.top\/wp-content\/uploads\/2023\/03\/image-373-768x751.png 768w, https:\/\/92it.top\/wp-content\/uploads\/2023\/03\/image-373-830x812.png 830w, https:\/\/92it.top\/wp-content\/uploads\/2023\/03\/image-373-230x225.png 230w, https:\/\/92it.top\/wp-content\/uploads\/2023\/03\/image-373-350x342.png 350w, https:\/\/92it.top\/wp-content\/uploads\/2023\/03\/image-373-480x469.png 480w\" sizes=\"(max-width: 319px) 100vw, 319px\" \/><\/figure><\/div>\n\n\n\n<p><strong>2 \u5f00\u59cb\u4f7f\u7528 TypeScript<\/strong><\/p>\n\n\n\n<p><strong>2.1 \u5b89\u88c5 TypeScript \u4f9d\u8d56\u73af\u5883<\/strong><\/p>\n\n\n\n<p>TypeScript \u5f00\u53d1\u73af\u5883\u642d\u5efa\u975e\u5e38\u7b80\u5355\uff0c\u5927\u90e8\u5206\u524d\u7aef\u5de5\u7a0b\u90fd\u96c6\u6210\u4e86 TypeScript \u53ea\u9700\u5b89\u88c5\u4f9d\u8d56\u589e\u52a0\u914d\u7f6e\u5373\u53ef\u3002\u6240\u6709\u524d\u7aef\u9879\u76ee\u90fd\u79bb\u4e0d\u5f00 NodeJS \u548c npm \u5de5\u5177\uff0cnpm \u547d\u4ee4\u5b89\u88c5 TypeScript\uff0c\u901a\u5e38TypeScript \u81ea\u5e26\u7684 tsc \u5e76\u4e0d\u80fd\u76f4\u63a5\u8fd0\u884cTypeScript \u4ee3\u7801\uff0c\u56e0\u6b64\u6211\u4eec\u8fd8\u4f1a\u5b89\u88c5 TypeScript \u7684\u8fd0\u884c\u65f6 <a href=\"https:\/\/www.zhihu.com\/search?q=ts-node&amp;search_source=Entity&amp;hybrid_search_source=Entity&amp;hybrid_search_extra=%7B%22sourceType%22%3A%22answer%22%2C%22sourceId%22%3A2811408216%7D\" target=\"_blank\" rel=\"noreferrer noopener\">ts-node<\/a><\/p>\n\n\n\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\" data-enlighter-theme=\"\" data-enlighter-highlight=\"\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\">npm install --save-dev typescript ts-node<\/pre>\n\n\n\n<p><strong>2.1.1 \u96c6\u6210 Babel<\/strong><\/p>\n\n\n\n<p>\u524d\u7aef\u5de5\u7a0b\u5927\u90fd\u79bb\u4e0d\u5f00 Babel \uff0c\u6211\u4eec\u9700\u8981\u5c06 TypScript \u548c Babel \u7ed3\u5408\u4f7f\u7528\uff0cTypeScript \u7f16\u8bd1\u5668\u8d1f\u8d23\u5bf9\u4ee3\u7801\u8fdb\u884c\u9759\u6001\u7c7b\u578b\u68c0\u67e5\uff0cBabel \u8d1f\u8d23\u5c06TypeScript \u4ee3\u7801\u8f6c\u8bd1\u4e3a\u53ef\u4ee5\u6267\u884c\u7684 JavaScript \u4ee3\u7801\uff1a<\/p>\n\n\n\n<div class=\"wp-block-image\"><figure class=\"aligncenter size-large is-resized\"><img loading=\"lazy\" decoding=\"async\" src=\"http:\/\/123.57.164.21\/wp-content\/uploads\/2023\/03\/image-374-1024x238.png\" alt=\"\" class=\"wp-image-10395\" width=\"481\" height=\"112\" srcset=\"https:\/\/92it.top\/wp-content\/uploads\/2023\/03\/image-374-1024x238.png 1024w, https:\/\/92it.top\/wp-content\/uploads\/2023\/03\/image-374-300x70.png 300w, https:\/\/92it.top\/wp-content\/uploads\/2023\/03\/image-374-768x178.png 768w, https:\/\/92it.top\/wp-content\/uploads\/2023\/03\/image-374-830x193.png 830w, https:\/\/92it.top\/wp-content\/uploads\/2023\/03\/image-374-230x53.png 230w, https:\/\/92it.top\/wp-content\/uploads\/2023\/03\/image-374-350x81.png 350w, https:\/\/92it.top\/wp-content\/uploads\/2023\/03\/image-374-480x111.png 480w, https:\/\/92it.top\/wp-content\/uploads\/2023\/03\/image-374.png 1266w\" sizes=\"(max-width: 481px) 100vw, 481px\" \/><\/figure><\/div>\n\n\n\n<p>Babel \u4e0e TypeScript \u7ed3\u5408\u7684\u5173\u952e\u4f9d\u8d56 @babel\/preset-typescript\uff0c\u5b83\u63d0\u4f9b\u4e86\u4ece TypeScript \u4ee3\u7801\u4e2d\u79fb\u9664\u7c7b\u578b\u76f8\u5173\u4ee3\u7801\uff08\u5982\uff0c\u7c7b\u578b\u6ce8\u89e3\uff0c\u63a5\u53e3\uff0c\u7c7b\u578b\u6587\u4ef6\u7b49\uff09\uff0c\u5e76\u5728 babel.config.js \u6587\u4ef6\u6dfb\u52a0\u914d\u7f6e\u9009\u9879\uff1a<\/p>\n\n\n\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\" data-enlighter-theme=\"\" data-enlighter-highlight=\"\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\">npm install -D @babel\/preset-typescript\n\n\/\/ babel.config.js\n{\n\"presets\n\n\": [\n\/\/ ...\n\"@babel\/preset-typescript\"\n]\n}<\/pre>\n\n\n\n<p><strong>2.1.2 \u96c6\u6210 ESlint<\/strong><\/p>\n\n\n\n<p>\u4ee3\u7801\u68c0\u67e5\u662f\u9879\u76ee\u7684\u91cd\u8981\u7ec4\u6210\u90e8\u5206\uff0cTypeScript \u81ea\u8eab\u7684\u7ea6\u675f\u76f8\u5bf9\u7b80\u5355\u53ea\u53ef\u4ee5\u53d1\u73b0\u4e00\u4e9b\u4ee3\u7801\u9519\u8bef\u5e76\u4e0d\u4f1a\u5e2e\u52a9\u6211\u4eec\u7edf\u4e00\u4ee3\u7801\u98ce\u683c\uff0c\u5f53\u9879\u76ee\u8d8a\u6765\u8d8a\u5e9e\u5927\uff0c\u5f00\u53d1\u4eba\u5458\u8d8a\u6765\u8d8a\u591a\u65f6\uff0c\u4ee3\u7801\u98ce\u683c\u7684\u7ea6\u675f\u8fd8\u662f\u5fc5\u4e0d\u53ef\u5c11\u7684\u3002\u6211\u4eec\u53ef\u4ee5\u501f\u52a9 ESLint\u5bf9\u4ee3\u7801\u98ce\u683c\u8fdb\u884c\u7ea6\u675f\uff0c\u4e3a\u4e86\u8ba9 eslint \u6765\u89e3\u6790 TypeScript \u4ee3\u7801\u6211\u4eec\u9700\u8981\u5b89\u88c5\u89e3\u6790\u5668 @typescript-eslint\/parser \u548c \u63d2\u4ef6 @typescript-eslint\/eslint-plugin\uff1a<\/p>\n\n\n\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\" data-enlighter-theme=\"\" data-enlighter-highlight=\"\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\">npm install --save-dev @typescript-eslint\/parser @typescript-eslint\/eslint-plugin<\/pre>\n\n\n\n<p>\u6ce8\u610f\uff1a @typescript-eslint\/<a rel=\"noreferrer noopener\" href=\"https:\/\/www.zhihu.com\/search?q=parser&amp;search_source=Entity&amp;hybrid_search_source=Entity&amp;hybrid_search_extra=%7B%22sourceType%22%3A%22answer%22%2C%22sourceId%22%3A2811408216%7D\" target=\"_blank\">parser<\/a> \u548c @typescript-eslint\/eslint-plugin \u5fc5\u987b\u4f7f\u7528\u76f8\u540c\u7684\u7248\u672c<br>\u5728 .eslintrc.js \u914d\u7f6e\u6587\u4ef6\u4e2d\u6dfb\u52a0\u9009\u9879\uff1a<\/p>\n\n\n\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\" data-enlighter-theme=\"\" data-enlighter-highlight=\"\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\">\"parser\": \"@typescript-eslint\/parser\",\n      \"plugins\": [\"@typescript-eslint\"],\n\n\n\/\/ \u53ef\u4ee5\u76f4\u63a5\u542f\u7528\u63a8\u8350\u7684\u89c4\u5219\n  \"extends\": [\n    \"eslint:recommended\",\n    \"plugin:@typescript-eslint\/recommended\"\n]\n\/\/ \u4e5f\u53ef\u4ee5\u9009\u62e9\u81ea\u5b9a\u4e49\u89c4\u5219\n\"rules\": {\n\"@typescript-eslint\/no-use-before-define\": \"error\",\n\/\/ ...\n}\n<\/pre>\n\n\n\n<p>\u81ea\u5b9a\u4e49\u89c4\u5219\u9009\u9879\u5177\u4f53\u89e3\u8bfb\uff1a<\/p>\n\n\n\n<div class=\"wp-block-image\"><figure class=\"aligncenter size-large is-resized\"><img loading=\"lazy\" decoding=\"async\" src=\"http:\/\/123.57.164.21\/wp-content\/uploads\/2023\/03\/image-375-631x1024.png\" alt=\"\" class=\"wp-image-10396\" width=\"371\" height=\"602\" srcset=\"https:\/\/92it.top\/wp-content\/uploads\/2023\/03\/image-375-631x1024.png 631w, https:\/\/92it.top\/wp-content\/uploads\/2023\/03\/image-375-185x300.png 185w, https:\/\/92it.top\/wp-content\/uploads\/2023\/03\/image-375-768x1247.png 768w, https:\/\/92it.top\/wp-content\/uploads\/2023\/03\/image-375-830x1348.png 830w, https:\/\/92it.top\/wp-content\/uploads\/2023\/03\/image-375-230x373.png 230w, https:\/\/92it.top\/wp-content\/uploads\/2023\/03\/image-375-350x568.png 350w, https:\/\/92it.top\/wp-content\/uploads\/2023\/03\/image-375-480x779.png 480w, https:\/\/92it.top\/wp-content\/uploads\/2023\/03\/image-375.png 872w\" sizes=\"(max-width: 371px) 100vw, 371px\" \/><\/figure><\/div>\n\n\n\n<p><strong>2.2 \u914d\u7f6e TypeScript<\/strong><\/p>\n\n\n\n<p>TypeScript \u672c\u8eab\u63d0\u4f9b\u4e86\u53ea\u4f7f\u7528\u53c2\u6570\u5728\u547d\u4ee4\u884c\u7f16\u8bd1 TypeScript \u6587\u4ef6\uff0c\u4f46\u662f\u5728\u5b9e\u9645\u9879\u76ee\u5f00\u53d1\u65f6\u6211\u4eec\u90fd\u4f1a\u4f7f\u7528 <a rel=\"noreferrer noopener\" href=\"https:\/\/www.zhihu.com\/search?q=tsconfig.json&amp;search_source=Entity&amp;hybrid_search_source=Entity&amp;hybrid_search_extra=%7B%22sourceType%22%3A%22answer%22%2C%22sourceId%22%3A2811408216%7D\" target=\"_blank\">tsconfig.json<\/a> \uff0c\u5982\u679c\u9879\u76ee\u4e2d\u6ca1\u6709\u6b64\u6587\u4ef6\uff0c\u53ef\u4ee5\u624b\u52a8\u521b\u5efa\u4e5f\u53ef\u4ee5\u4f7f\u7528\u547d\u4ee4\u884c\u521b\u5efa\uff08tsc \u2014init\uff09\u3002\u4f7f\u7528 TypeScript \u521d\u671f\u4ec5\u9700\u8981\u4e00\u4efd\u9ed8\u8ba4\u7684 tsconfig.json \u5373\u53ef\uff0c\u5b83\u5305\u542b\u4e86\u4e00\u4e0b\u57fa\u672c\u7684\u7f16\u8bd1\u9009\u9879\u76f8\u5173\u4fe1\u606f\uff0c\u5f53\u6211\u4eec\u9700\u8981\u5b9a\u5236\u7f16\u8bd1\u9009\u9879\u65f6\u5c31\u9700\u8981\u53bb\u4e86\u89e3\u6bcf\u4e00\u9879\u5177\u4f53\u7684\u542b\u4e49\uff0c\u7f16\u8bd1\u9009\u9879\u89e3\u8bfb\u5982\u4e0b\uff1a<\/p>\n\n\n\n<div class=\"wp-block-image\"><figure class=\"aligncenter size-large is-resized\"><img loading=\"lazy\" decoding=\"async\" src=\"http:\/\/123.57.164.21\/wp-content\/uploads\/2023\/03\/image-376-1024x682.png\" alt=\"\" class=\"wp-image-10397\" width=\"549\" height=\"365\" srcset=\"https:\/\/92it.top\/wp-content\/uploads\/2023\/03\/image-376-1024x682.png 1024w, https:\/\/92it.top\/wp-content\/uploads\/2023\/03\/image-376-300x200.png 300w, https:\/\/92it.top\/wp-content\/uploads\/2023\/03\/image-376-768x512.png 768w, https:\/\/92it.top\/wp-content\/uploads\/2023\/03\/image-376-830x553.png 830w, https:\/\/92it.top\/wp-content\/uploads\/2023\/03\/image-376-230x153.png 230w, https:\/\/92it.top\/wp-content\/uploads\/2023\/03\/image-376-350x233.png 350w, https:\/\/92it.top\/wp-content\/uploads\/2023\/03\/image-376-480x320.png 480w, https:\/\/92it.top\/wp-content\/uploads\/2023\/03\/image-376.png 1276w\" sizes=\"(max-width: 549px) 100vw, 549px\" \/><\/figure><\/div>\n\n\n\n<p>2.\u4e25\u683c\u7684\u7c7b\u578b\u68c0\u67e5\u9009\u9879\uff1a<\/p>\n\n\n\n<ul><li>strict: \u662f\u5426\u542f\u7528\u4e25\u683c\u7c7b\u578b\u68c0\u67e5\u9009\u9879\uff0c\u53ef\u9009 ture | false<\/li><li>allowUnreachableCode\uff1a \u662f\u5426\u5141\u8bb8\u4e0d\u53ef\u8fbe\u7684\u4ee3\u7801\u51fa\u73b0\uff0c\u53ef\u9009 ture | false<\/li><li>allowUnusedLabels: \u662f\u5426\u62a5\u544a\u672a\u4f7f\u7528\u7684\u6807\u7b7e\u9519\u8bef\uff0c\u53ef\u9009 ture | false<\/li><li>noImplicitAny: \u5f53\u5728\u8868\u8fbe\u5f0f\u548c\u58f0\u660e\u4e0a\u6709\u9690\u5f0f\u7684 any \u65f6\u662f\u5426\u62a5\u9519\uff0c\u53ef\u9009 ture | false<\/li><li>strictNullChecks: \u662f\u5426\u542f\u7528\u4e25\u683c\u7684 null \u68c0\u67e5\uff0c\u53ef\u9009 ture | false<\/li><li>noImplicitThis: \u5f53 this \u8868\u8fbe\u5f0f\u7684\u503c\u4e3a any \u65f6\uff0c\u751f\u6210\u4e00\u4e2a\u9519\u8bef\uff0c\u53ef\u9009 ture | false<\/li><li>alwaysStrict: \u662f\u5426\u4ee5\u4e25\u683c\u6a21\u5f0f\u68c0\u67e5\u6bcf\u4e2a\u6a21\u5757\uff0c\u5e76\u5728\u6bcf\u4e2a\u6587\u4ef6\u91cc\u52a0\u5165 <a rel=\"noreferrer noopener\" href=\"https:\/\/www.zhihu.com\/search?q=use%20strict&amp;search_source=Entity&amp;hybrid_search_source=Entity&amp;hybrid_search_extra=%7B%22sourceType%22%3A%22answer%22%2C%22sourceId%22%3A2811408216%7D\" target=\"_blank\">use strict<\/a>\uff0c\u53ef\u9009 ture | false<\/li><li>noImplicitReturns: \u5f53\u51fd\u6570\u6709\u7684\u5206\u652f\u6ca1\u6709\u8fd4\u56de\u503c\u65f6\u662f\u5426\u4f1a\u62a5\u9519\uff0c\u53ef\u9009 ture | false<\/li><li>noFallthroughCasesInSwitch: \u8868\u793a\u662f\u5426\u62a5\u544a switch \u8bed\u53e5\u7684 case \u5206\u652f\u843d\u7a7a\uff08fallthrough\uff09\u9519\u8bef\uff1b<\/li><\/ul>\n\n\n\n<p>3.\u6a21\u5757\u89e3\u6790\u9009\u9879\uff1a<\/p>\n\n\n\n<ul><li>moduleResolution: \u6a21\u5757\u89e3\u6790\u7b56\u7565\u9ed8\u8ba4\u4e3a node \u6bd4\u8f83\u901a\u7528\u7684\u4e00\u79cd\u65b9\u5f0f\u57fa<\/li><li>commonjs \u6a21\u5757\u6807\u51c6\uff0c\u53e6\u4e00\u79cd\u662f classic \u9002\u7528\u4e8e\u5176\u4ed6 module \u6807\u51c6\uff0c\u5982 amd\u3001 umd\u3001 <a rel=\"noreferrer noopener\" href=\"https:\/\/www.zhihu.com\/search?q=esnext&amp;search_source=Entity&amp;hybrid_search_source=Entity&amp;hybrid_search_extra=%7B%22sourceType%22%3A%22answer%22%2C%22sourceId%22%3A2811408216%7D\" target=\"_blank\">esnext<\/a> \u7b49\u7b49<\/li><li>baseUrl: \u201c.\/\u201c \u7528\u4e8e\u89e3\u6790\u975e\u76f8\u5bf9\u6a21\u5757\u540d\u79f0\u7684\u6839\u76ee\u5f55<\/li><li>paths: \u6a21\u5757\u540d\u5230\u57fa\u4e8e baseUrl \u7684\u8def\u5f84\u6620\u5c04\u7684\u5217\u8868\uff0c\u683c\u5f0f {}<\/li><li>rootDirs: \u6839\u6587\u4ef6\u5939\u5217\u8868\uff0c\u5176\u505a\u597d\u5185\u5bb9\u8868\u793a\u9879\u76ee\u8fd0\u884c\u65f6\u7684\u7ed3\u679c\u5185\u5bb9\uff0c\u683c\u5f0f []<\/li><li>typeRoots: \u5305\u542b\u7c7b\u578b\u58f0\u660e\u7684\u6587\u4ef6\u5217\u8868\uff0c\u683c\u5f0f [\u201c.\/types\u201d] \uff0c\u76f8\u5bf9\u4e8e\u914d\u7f6e\u6587\u4ef6\u7684\u8def\u5f84\u89e3\u6790\uff1b<\/li><li>allowSyntheticDefaultImports: \u662f\u5426\u5141\u8bb8\u4ece\u6ca1\u6709\u8bbe\u7f6e\u9ed8\u8ba4\u5bfc\u51fa\u7684\u6a21\u5757\u4e2d\u9ed8\u8ba4\u5bfc\u5165<\/li><\/ul>\n\n\n\n<p>4.Source Map \u9009\u9879\uff1a<\/p>\n\n\n\n<ul><li>sourceRoot\uff1a .\/ \u6307\u5b9a\u8c03\u8bd5\u5668\u5e94\u8be5\u627e\u5230 TypeScript \u6587\u4ef6\u800c\u4e0d\u662f\u6e90\u6587\u4ef6\u7684\u4f4d\u7f6e<\/li><li>mapRoot: .\/ \u6307\u5b9a\u8c03\u8bd5\u5668\u5e94\u8be5\u627e\u5230\u6620\u5c04\u6587\u4ef6\u800c\u4e0d\u662f\u751f\u6210\u6587\u4ef6\u7684\u4f4d\u7f6e<\/li><li>inlineSourceMap: \u662f\u5426\u751f\u6210\u5355\u4e2a sourceMap \u6587\u4ef6\uff0c\u4e0d\u662f\u5c06 sourceMap \u751f\u6210\u4e0d\u540c\u7684\u6587\u4ef6<\/li><li>inlineSources: \u662f\u5426\u5c06\u4ee3\u7801\u4e0e sourceMap \u751f\u6210\u5230\u4e00\u4e2a\u6587\u4ef6\u4e2d\uff0c\u8981\u6c42\u540c\u65f6\u8bbe\u7f6e inlineSourceMap \u548c sourceMap \u5c5e\u6027<\/li><\/ul>\n\n\n\n<p>5.\u5176\u5b83\u9009\u9879\uff1a<\/p>\n\n\n\n<ul><li>experimentalDecorators: \u662f\u5426\u542f\u7528\u88c5\u9970\u5668<\/li><li>emitDecoratorMetadata: \u662f\u5426\u4e3a\u88c5\u9970\u5668\u63d0\u4f9b\u5143\u6570\u636e\u7684\u652f\u6301<\/li><\/ul>\n\n\n\n<p>6.\u8fd8\u53ef\u4ee5\u4f7f\u7528include \u548c exclude \u9009\u9879\u6765\u6307\u5b9a\u7f16\u8bd1\u5668\u9700\u8981\u548c\u4e0d\u9700\u8981\u7f16\u8bd1\u7684\u6587\u4ef6\uff0c\u4e00\u822c\u589e\u52a0\u5fc5\u8981\u7684 exclude \u6587\u4ef6\u4f1a\u63d0\u5347\u7f16\u8bd1\u6027\u80fd\uff1a<\/p>\n\n\n\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\" data-enlighter-theme=\"\" data-enlighter-highlight=\"\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\">\"exclude\": [\n    \"node_modules\",\n    \"dist\"\n...\n  ],<\/pre>\n\n\n\n<p><strong>2.3 TypeScript \u7c7b\u578b\u6ce8\u89e3<\/strong><\/p>\n\n\n\n<p>\u719f\u6089\u4e86 TypeScript \u7684\u76f8\u5173\u914d\u7f6e\uff0c\u518d\u6765\u770b\u4e00\u770b TypeScript \u63d0\u4f9b\u7684\u57fa\u672c\u7c7b\u578b\uff0c\u4e0b\u56fe\u662f\u4e0e ES6 \u7c7b\u578b\u7684\u5bf9\u6bd4\uff1a<\/p>\n\n\n\n<div class=\"wp-block-image\"><figure class=\"aligncenter size-large is-resized\"><img loading=\"lazy\" decoding=\"async\" src=\"http:\/\/123.57.164.21\/wp-content\/uploads\/2023\/03\/image-377-1024x696.png\" alt=\"\" class=\"wp-image-10399\" width=\"450\" height=\"305\" srcset=\"https:\/\/92it.top\/wp-content\/uploads\/2023\/03\/image-377-1024x696.png 1024w, https:\/\/92it.top\/wp-content\/uploads\/2023\/03\/image-377-300x204.png 300w, https:\/\/92it.top\/wp-content\/uploads\/2023\/03\/image-377-768x522.png 768w, https:\/\/92it.top\/wp-content\/uploads\/2023\/03\/image-377-830x564.png 830w, https:\/\/92it.top\/wp-content\/uploads\/2023\/03\/image-377-230x156.png 230w, https:\/\/92it.top\/wp-content\/uploads\/2023\/03\/image-377-350x238.png 350w, https:\/\/92it.top\/wp-content\/uploads\/2023\/03\/image-377-480x326.png 480w, https:\/\/92it.top\/wp-content\/uploads\/2023\/03\/image-377.png 1330w\" sizes=\"(max-width: 450px) 100vw, 450px\" \/><\/figure><\/div>\n\n\n\n<p>\u56fe\u4e2d\u84dd\u8272\u7684\u4e3a\u57fa\u672c\u7c7b\u578b\uff0c\u7ea2\u8272\u4e3a TypeScript \u652f\u6301\u7684\u7279\u6b8a\u7c7b\u578b<\/p>\n","protected":false},"excerpt":{"rendered":"<p>\u968f\u7740\u524d\u7aef\u5de5\u7a0b\u5316\u7684\u5feb\u901f\u53d1\u5c55\uff0c TypeScript \u53d8\u5f97\u8d8a\u6765\u8d8a\u53d7\u6b22\u8fce\uff0c\u5b83\u5df2\u7ecf\u6210\u4e3a\u524d\u7aef\u5f00\u53d1\u4eba\u5458\u5fc5\u5907\u6280\u80fd\u3002 Type [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[24],"tags":[],"_links":{"self":[{"href":"https:\/\/92it.top\/index.php?rest_route=\/wp\/v2\/posts\/10392"}],"collection":[{"href":"https:\/\/92it.top\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/92it.top\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/92it.top\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/92it.top\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=10392"}],"version-history":[{"count":2,"href":"https:\/\/92it.top\/index.php?rest_route=\/wp\/v2\/posts\/10392\/revisions"}],"predecessor-version":[{"id":10400,"href":"https:\/\/92it.top\/index.php?rest_route=\/wp\/v2\/posts\/10392\/revisions\/10400"}],"wp:attachment":[{"href":"https:\/\/92it.top\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=10392"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/92it.top\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=10392"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/92it.top\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=10392"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}