{"id":2540,"date":"2020-04-01T21:22:50","date_gmt":"2020-04-01T13:22:50","guid":{"rendered":"http:\/\/www.yuguoxy.com\/geekhome\/?p=2540"},"modified":"2026-08-18T12:35:26","modified_gmt":"2026-08-18T04:35:26","slug":"typescript%e4%bb%8b%e7%bb%8d","status":"publish","type":"post","link":"https:\/\/ai.zhousir.top\/?p=2540","title":{"rendered":"TypeScript\u4ecb\u7ecd"},"content":{"rendered":"<section id=\"wenyan\" style=\"font-family: system-ui, 'Apple Color Emoji', 'Segoe UI', 'Segoe UI Symbol', 'Noto Sans', Roboto, sans-serif; line-height: 1.75; font-size: 16px; color: #000000; caret-color: #000000;\" data-provider=\"WenYan\">\n<p style=\"margin: 1em 0px;\">\u5b66 <strong style=\"color: #4870ac;\">TypeScript<\/strong> \u662f\u4e0d\u662f\u5c31\u4e0d\u7528\u5b66 JavaScript \u4e86\uff1fVue 3.0 \u7528 TS \u91cd\u5199\u4e4b\u540e\u662f\u4e0d\u662f\u4e0d\u7528 TS \u4e0d\u884c\uff1f\u5b83\u9760\u8c31\u5417\uff1f\u8fd9\u7c7b\u72b9\u8c6b\u5f80\u5f80\u6765\u81ea\u8bef\u89e3\uff1a\u5b83\u4e0d\u662f JS \u7684\u5b6a\u751f\u5144\u5f1f\uff0c\u4e5f\u4e0d\u662f\u65b0\u6276\u6301\u7684\u53e6\u4e00\u95e8\u8bed\u8a00\uff0c\u800c\u662f JavaScript \u7684<strong style=\"color: #4870ac;\">\u8d85\u96c6<\/strong>\u2014\u2014\u52a0\u4e86\u88c5\u5907\u7684\u8fdb\u5316\u7248 JS\u3002<\/p>\n<p style=\"margin: 1em 0px;\">JS \u6709\u7684\u5b83\u90fd\u6709\uff0c\u800c\u4e14\u7c7b\u578b\u68c0\u67e5\u80fd\u5728\u7f16\u5199\u671f\u62e6\u4f4f\u4e00\u6279\u8fd0\u884c\u65f6\u624d\u4f1a\u7206\u7684\u9519\u3002\u5b83\u7d27\u8ddf ECMAScript\uff0cES6\/7\/8\/9 \u90fd\u652f\u6301\uff0c\u8fd8\u5728\u8bed\u8a00\u5c42\u9762\u62d3\u5c55\u4e86\u679a\u4e3e\u3001\u7c7b\u7684\u90e8\u5206\u8bed\u6cd5\u3002\u914d\u5408 VSCode \u548c TSLint\uff0c\u5927\u578b\u534f\u4f5c\u9879\u76ee\u91cc\u5c24\u5176\u660e\u663e\u3002<\/p>\n<table style=\"display: table; text-align: left; overflow: auto; border-collapse: collapse; margin: 1.4em auto; max-width: 100%; table-layout: fixed; overflow-wrap: break-word; word-break: break-all;\" width=\"800\">\n<thead>\n<tr>\n<th style=\"border: 1px solid #d9dfe4; padding: 9px 12px; font-size: 0.75em; line-height: 22px; vertical-align: top; text-align: center; font-weight: bold; color: #4870ac; background: #f7f7f7;\">\u7591\u95ee<\/th>\n<th style=\"border: 1px solid #d9dfe4; padding: 9px 12px; font-size: 0.75em; line-height: 22px; vertical-align: top; text-align: center; font-weight: bold; color: #4870ac; background: #f7f7f7;\">\u5b9e\u9645\u60c5\u51b5<\/th>\n<\/tr>\n<\/thead>\n<tbody>\n<tr>\n<td style=\"border: 1px solid #d9dfe4; padding: 9px 12px; font-size: 0.75em; line-height: 22px; vertical-align: top;\">\u8981\u4e0d\u8981\u8fd8\u5b66 JS<\/td>\n<td style=\"border: 1px solid #d9dfe4; padding: 9px 12px; font-size: 0.75em; line-height: 22px; vertical-align: top;\">\u8981\u3002TS \u662f JS \u8d85\u96c6\uff0c\u539f\u7406\u4ecd\u662f JS<\/td>\n<\/tr>\n<tr>\n<td style=\"border: 1px solid #d9dfe4; padding: 9px 12px; font-size: 0.75em; line-height: 22px; vertical-align: top;\">\u80fd\u4e0d\u80fd\u4ee3\u66ff Babel<\/td>\n<td style=\"border: 1px solid #d9dfe4; padding: 9px 12px; font-size: 0.75em; line-height: 22px; vertical-align: top;\">\u53ef\u4ee5\u628a\u4ee3\u7801\u7f16\u5230\u6307\u5b9a ES \u7248\u672c\uff0c\u8fd9\u65b9\u9762\u80fd\u6253\u5e73<\/td>\n<\/tr>\n<tr>\n<td style=\"border: 1px solid #d9dfe4; padding: 9px 12px; font-size: 0.75em; line-height: 22px; vertical-align: top;\">\u9002\u5408\u4ec0\u4e48\u9879\u76ee<\/td>\n<td style=\"border: 1px solid #d9dfe4; padding: 9px 12px; font-size: 0.75em; line-height: 22px; vertical-align: top;\">\u591a\u4eba\u534f\u4f5c\u3001\u5f00\u6e90\u5de5\u5177\/\u7ec4\u4ef6\u5e93\u3001\u5bf9\u8d28\u91cf\u8981\u6c42\u9ad8\u7684\u9879\u76ee<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<h2 style=\"padding: 1px 12.5px; color: #ffffff; margin: 1.2em 0px 1em; border-radius: 4px; display: inline-block; background-color: #4870ac; font-size: 1.3em;\">\u4e00\u3001\u5b83\u4e0d\u662f\u65b0\u8bed\u8a00\uff0c\u662f JavaScript \u7684\u8d85\u96c6<\/h2>\n<p style=\"margin: 1em 0px;\">JS \u6ca1\u6709\u7684\uff0cTS \u4e5f\u6709\uff0c\u800c\u4e14\u5f88\u957f\u4e00\u6bb5\u65f6\u95f4\u4e0d\u4f1a\u88ab JS \u8d76\u4e0a\u3002\u4f5c\u4e3a\u8d85\u96c6\uff0c\u5b83\u59cb\u7ec8\u8ddf ECMAScript\uff1a\u65b0\u8bed\u6cd5\u90fd\u652f\u6301\uff0c\u5e76\u589e\u52a0\u4e86\u679a\u4e3e\uff08Enum\uff09\u8fd9\u7c7b\u5e38\u89c1\u7c7b\u578b\uff0c\u5bf9 Class \u4e5f\u5b9e\u73b0\u4e86\u4e00\u4e9b ES6 \u6807\u51c6\u91cc\u6ca1\u5b9a\u6b7b\u7684\u8bed\u6cd5\u3002<\/p>\n<p style=\"margin: 1em 0px;\">\u8ffd\u65b0\u7684\u5f00\u53d1\u8005\u5df2\u7ecf\u5728\u7528 ES6\/7\/8\/9\u3002\u8981\u8ba9\u8fd9\u4e9b\u4ee3\u7801\u8dd1\u5728\u975e\u73b0\u4ee3\u6d4f\u89c8\u5668\u4e0a\uff0c\u901a\u5e38\u9760 Babel \u8f6c\u5230 ES3\/5\u3002TS \u53ef\u4ee5\u5b8c\u5168\u4e0d\u7528 Babel\uff0c\u5c31\u80fd\u7f16\u5230\u6307\u5b9a\u7248\u672c\uff0c\u8fd9\u4e00\u70b9\u548c JavaScript \u6253\u5e73\u3002<\/p>\n<h2 style=\"padding: 1px 12.5px; color: #ffffff; margin: 1.2em 0px 1em; border-radius: 4px; display: inline-block; background-color: #4870ac; font-size: 1.3em;\">\u4e8c\u3001\u7c7b\u578b\u7cfb\u7edf\uff1a\u5199\u4ee3\u7801\u65f6\u5c31\u80fd\u53d1\u73b0\u9519\u8bef<\/h2>\n<p style=\"margin: 1em 0px;\">\u6700\u5927\u4f18\u52bf\u662f\u7c7b\u578b\u7cfb\u7edf\uff0c\u8fd9\u4e5f\u662f\u540d\u5b57\u91cc Type \u7684\u6765\u6e90\u3002JS \u5f88\u591a\u9519\u8981\u5230\u8fd0\u884c\u65f6\u624d\u53d1\u73b0\uff0c\u4f8b\u5982\uff1a\u8bbf\u95ee\u5bf9\u8c61\u6ca1\u6709\u7684\u5c5e\u6027\u3001\u8c03\u7528\u51fd\u6570\u5c11\u4f20\u53c2\u6570\u3001\u8fd4\u56de\u503c\u662f\u5b57\u7b26\u4e32\u5374\u5f53\u6570\u503c\u7528\u3002\u8fd9\u4e9b\u95ee\u9898\u5728 TS \u91cc\u90fd\u4e0d\u7b97\u4e8b\uff0c\u7f16\u5199\u65f6\u5c31\u80fd\u6807\u51fa\u6765\u3002<\/p>\n<p style=\"margin: 1em 0px;\"><a href=\"https:\/\/ai.zhousir.top\/wp-content\/uploads\/2020\/04\/\u256c\u0432\u2568\u253c\u255c\u256a\u2550\u255d_20200401211837.png\" rel=\"fancybox\"><img decoding=\"async\" loading=\"lazy\" class=\"alignnone  wp-image-2542\" src=\"https:\/\/ai.zhousir.top\/wp-content\/uploads\/2020\/04\/\u256c\u0432\u2568\u253c\u255c\u256a\u2550\u255d_20200401211837.png\" alt=\"\u256c\u0432\u2568\u253c\u255c\u256a\u2550\u255d_20200401211837\" width=\"272\" height=\"213\"><\/a><\/p>\n<p style=\"margin: 1em 0px;\"><code style=\"font-family: Menlo, Monaco, Consolas, 'Liberation Mono', 'Roboto Mono', 'Courier New', 'Microsoft YaHei', monospace; color: #4870ac; font-size: 0.9em; font-weight: normal; overflow-wrap: break-word; padding: 2px 4px; border-radius: 3px; margin: 2px; background-color: #f6f8fa; word-break: break-all;\">interface<\/code> \u5b9a\u4e49\u7684\u662f\u5bf9\u7ed3\u6784\u7684\u63cf\u8ff0\u3002\u4e0b\u9762\u7684 <code style=\"font-family: Menlo, Monaco, Consolas, 'Liberation Mono', 'Roboto Mono', 'Courier New', 'Microsoft YaHei', monospace; color: #4870ac; font-size: 0.9em; font-weight: normal; overflow-wrap: break-word; padding: 2px 4px; border-radius: 3px; margin: 2px; background-color: #f6f8fa; word-break: break-all;\">info<\/code> \u7528 ES6 \u7684 <code style=\"font-family: Menlo, Monaco, Consolas, 'Liberation Mono', 'Roboto Mono', 'Courier New', 'Microsoft YaHei', monospace; color: #4870ac; font-size: 0.9em; font-weight: normal; overflow-wrap: break-word; padding: 2px 4px; border-radius: 3px; margin: 2px; background-color: #f6f8fa; word-break: break-all;\">const<\/code> \u58f0\u660e\uff0c\u901a\u8fc7 <code style=\"font-family: Menlo, Monaco, Consolas, 'Liberation Mono', 'Roboto Mono', 'Courier New', 'Microsoft YaHei', monospace; color: #4870ac; font-size: 0.9em; font-weight: normal; overflow-wrap: break-word; padding: 2px 4px; border-radius: 3px; margin: 2px; background-color: #f6f8fa; word-break: break-all;\">info: Info<\/code> \u6307\u5b9a\u8981\u5b9e\u73b0 Info \u7ed3\u6784\uff0c\u5c31\u5fc5\u987b\u5305\u542b name \u548c age\u3002\u5b9e\u9645\u4ee3\u7801\u53ea\u6709 name\uff0c\u4e8e\u662f\u88ab\u7ea2\u6ce2\u6d6a\u7ebf\u6807\u51fa\u3002\u9f20\u6807\u653e\u4e0a\u53bb\uff0cVSCode \u4f1a\u63d0\u793a\uff1a<\/p>\n<p style=\"margin: 1em 0px;\"><a href=\"https:\/\/ai.zhousir.top\/wp-content\/uploads\/2020\/04\/\u256c\u0432\u2568\u253c\u255c\u256a\u2550\u255d_20200401211939.png\" rel=\"fancybox\"><img decoding=\"async\" loading=\"lazy\" class=\"alignnone size-full wp-image-2543\" src=\"https:\/\/ai.zhousir.top\/wp-content\/uploads\/2020\/04\/\u256c\u0432\u2568\u253c\u255c\u256a\u2550\u255d_20200401211939.png\" alt=\"\u256c\u0432\u2568\u253c\u255c\u256a\u2550\u255d_20200401211939\" width=\"996\" height=\"257\"><\/a><\/p>\n<p style=\"margin: 1em 0px;\">\u8fd9\u4e9b\u6982\u5ff5\u540e\u9762\u7ae0\u8282\u4f1a\u7ec6\u8bb2\u3002\u914d\u5408 VSCode \u8fd9\u7c7b\u7f16\u8f91\u5668\uff0c\u53ef\u4ee5\u9760\u63d0\u793a\u6109\u5feb\u5730\u5199 TS\u3002\u6df1\u53d7\u524d\u7aef\u559c\u7231\u7684 VSCode \u672c\u8eab\u4e5f\u662f\u7528 TypeScript \u5f00\u53d1\u7684\uff08<a href=\"https:\/\/github.com\/Microsoft\/vscode\">VSCode<\/a>\uff09\u3002<\/p>\n<h2 style=\"padding: 1px 12.5px; color: #ffffff; margin: 1.2em 0px 1em; border-radius: 4px; display: inline-block; background-color: #4870ac; font-size: 1.3em;\">\u4e09\u3001\u51fd\u6570\u91cd\u8f7d\uff1a\u522b\u7528\u5176\u4ed6\u8bed\u8a00\u7684\u601d\u7ef4\u786c\u5957<\/h2>\n<p style=\"margin: 1em 0px;\">\u505a\u4e86\u5f88\u4e45 C++\u3001Java \u7684\u540e\u7aef\uff0c\u53ef\u80fd\u5bf9 TS \u6709\u8bef\u89e3\u3002\u522b\u7684\u8bed\u8a00\u91cc\u53ef\u4ee5\u5b9a\u4e49\u591a\u4e2a\u540c\u540d\u51fd\u6570\uff0c\u9760\u53c2\u6570\u4e2a\u6570\u3001\u7c7b\u578b\u533a\u5206\uff1bTS \u4e5f\u6709\u91cd\u8f7d\uff0c\u4f46\u76ee\u7684\u662f\u5e2e\u7f16\u8bd1\u5668\u77e5\u9053\uff1a\u7ed9\u540c\u4e00\u4e2a\u51fd\u6570\u4f20\u5165\u4e0d\u540c\u53c2\u6570\u65f6\uff0c\u8fd4\u56de\u503c\u662f\u4ec0\u4e48\u60c5\u51b5\u3002JS \u91cc\u8981\u5728\u51fd\u6570\u4f53\u5185\u81ea\u5df1\u5224\u65ad\u3002\u4f8b\u5982\uff1a<\/p>\n<pre style=\"overflow: auto hidden; word-break: normal; white-space: pre; tab-size: 2; border-radius: 5px; line-height: 2; margin: 1em 0.5em; padding: 0.5em; box-shadow: rgba(0, 0, 0, 0.55) 0px 1px 5px; font-size: 12px; background: #002b36; max-width: 100%; overflow-wrap: normal;\"><code class=\"hljs\" style=\"word-break: normal; white-space: nowrap; tab-size: 2; font-size: 12px; font-family: Menlo, Monaco, Consolas, 'Liberation Mono', 'Roboto Mono', 'Courier New', 'Microsoft YaHei', monospace; display: block; overflow-x: auto; margin: 0.5em; padding: 3px 5px; color: #93a1a1; background: #002b36; overflow-wrap: normal;\"><span class=\"token keyword\">const<\/span> <span class=\"token function-variable function\">getResult<\/span> <span class=\"token operator\">=<\/span> input <span class=\"token operator\">=&gt;<\/span> <span class=\"token punctuation\">{<\/span>\n    <span class=\"token keyword\">if<\/span> <span class=\"token punctuation\">(<\/span><span class=\"token keyword\">typeof<\/span> input <span class=\"token operator\">===<\/span> <span class=\"token string\">'string'<\/span><span class=\"token punctuation\">)<\/span> <span class=\"token keyword\">return<\/span> input<span class=\"token punctuation\">.<\/span>length\n    <span class=\"token keyword\">else<\/span> <span class=\"token keyword\">if<\/span> <span class=\"token punctuation\">(<\/span><span class=\"token keyword\">typeof<\/span> input <span class=\"token operator\">===<\/span> <span class=\"token string\">'number'<\/span><span class=\"token punctuation\">)<\/span> <span class=\"token keyword\">return<\/span> input<span class=\"token punctuation\">.<\/span><span class=\"token function\">toString<\/span><span class=\"token punctuation\">(<\/span><span class=\"token punctuation\">)<\/span>\n    <span class=\"token keyword\">else<\/span> <span class=\"token keyword\">return<\/span> input\n<span class=\"token punctuation\">}<\/span><\/code><\/pre>\n<p style=\"margin: 1em 0px;\">\u8f93\u5165\u5b57\u7b26\u4e32\u5219\u8fd4\u56de\u957f\u5ea6\uff1b\u6570\u503c\u5219\u53d8\u6210\u5b57\u7b26\u4e32\uff1b\u5426\u5219\u539f\u6837\u8fd4\u56de\u3002\u8fd4\u56de\u7c7b\u578b\u968f\u8f93\u5165\u800c\u53d8\uff0c\u4f7f\u7528\u65f6\u5bb9\u6613\u7528\u9519\uff1a\u8f93\u5165 123 \u5e94\u8fd4\u56de\u5b57\u7b26\u4e32 &#8216;123&#8217;\uff0c\u518d\u8c03 toFixed \u8fd0\u884c\u5c31\u4f1a\u62a5\u9519\u3002\u7528 TS \u4e66\u5199\u65f6\uff0c\u5199\u4ee3\u7801\u9636\u6bb5\u5c31\u4f1a\u544a\u8bc9\u4f60\uff1a<\/p>\n<pre style=\"overflow: auto hidden; word-break: normal; white-space: pre; tab-size: 2; border-radius: 5px; line-height: 2; margin: 1em 0.5em; padding: 0.5em; box-shadow: rgba(0, 0, 0, 0.55) 0px 1px 5px; font-size: 12px; background: #002b36; max-width: 100%; overflow-wrap: normal;\"><code class=\"hljs\" style=\"word-break: normal; white-space: nowrap; tab-size: 2; font-size: 12px; font-family: Menlo, Monaco, Consolas, 'Liberation Mono', 'Roboto Mono', 'Courier New', 'Microsoft YaHei', monospace; display: block; overflow-x: auto; margin: 0.5em; padding: 3px 5px; color: #93a1a1; background: #002b36; overflow-wrap: normal;\"><span class=\"token keyword\">function<\/span> <span class=\"token function\">getResult<\/span> <span class=\"token punctuation\">(<\/span>input<span class=\"token punctuation\">:<\/span> <span class=\"token keyword\">string<\/span><span class=\"token punctuation\">)<\/span><span class=\"token punctuation\">:<\/span> <span class=\"token keyword\">number<\/span>\n<span class=\"token keyword\">function<\/span> <span class=\"token function\">getResult<\/span> <span class=\"token punctuation\">(<\/span>input<span class=\"token punctuation\">:<\/span> <span class=\"token keyword\">number<\/span><span class=\"token punctuation\">)<\/span><span class=\"token punctuation\">:<\/span> <span class=\"token keyword\">string<\/span>\n<span class=\"token keyword\">function<\/span> getResult <span class=\"token operator\">&lt;<\/span>T<span class=\"token operator\">&gt;<\/span><span class=\"token punctuation\">(<\/span>input<span class=\"token punctuation\">:<\/span> T<span class=\"token punctuation\">)<\/span><span class=\"token punctuation\">:<\/span> T\n<span class=\"token keyword\">function<\/span> <span class=\"token function\">getResult<\/span> <span class=\"token punctuation\">(<\/span>input<span class=\"token punctuation\">:<\/span> <span class=\"token keyword\">any<\/span><span class=\"token punctuation\">)<\/span><span class=\"token punctuation\">:<\/span> <span class=\"token keyword\">any<\/span> <span class=\"token punctuation\">{<\/span>\n  <span class=\"token keyword\">if<\/span> <span class=\"token punctuation\">(<\/span><span class=\"token keyword\">typeof<\/span> input <span class=\"token operator\">===<\/span> <span class=\"token string\">'string'<\/span><span class=\"token punctuation\">)<\/span> <span class=\"token keyword\">return<\/span> input<span class=\"token punctuation\">.<\/span>length\n  <span class=\"token keyword\">else<\/span> <span class=\"token keyword\">if<\/span> <span class=\"token punctuation\">(<\/span><span class=\"token keyword\">typeof<\/span> input <span class=\"token operator\">===<\/span> <span class=\"token string\">'number'<\/span><span class=\"token punctuation\">)<\/span> <span class=\"token keyword\">return<\/span> input<span class=\"token punctuation\">.<\/span><span class=\"token function\">toString<\/span><span class=\"token punctuation\">(<\/span><span class=\"token punctuation\">)<\/span>\n  <span class=\"token keyword\">else<\/span> <span class=\"token keyword\">return<\/span> input\n<span class=\"token punctuation\">}<\/span><\/code><\/pre>\n<p style=\"margin: 1em 0px;\">\u524d\u4e09\u884c\u7ec4\u6210\u51fd\u6570\u91cd\u8f7d\uff0c\u7b2c\u56db\u884c\u5f00\u59cb\u662f\u5b9e\u9645\u51fd\u6570\u4f53\u3002\u518d\u8c03\u7528 getResult\uff1a<\/p>\n<p style=\"margin: 1em 0px;\"><a href=\"https:\/\/ai.zhousir.top\/wp-content\/uploads\/2020\/04\/\u256c\u0432\u2568\u253c\u255c\u256a\u2550\u255d_20200401212017.png\" rel=\"fancybox\"><img decoding=\"async\" loading=\"lazy\" class=\"alignnone size-full wp-image-2544\" src=\"https:\/\/ai.zhousir.top\/wp-content\/uploads\/2020\/04\/\u256c\u0432\u2568\u253c\u255c\u256a\u2550\u255d_20200401212017.png\" alt=\"\u256c\u0432\u2568\u253c\u255c\u256a\u2550\u255d_20200401212017\" width=\"688\" height=\"155\"><\/a><\/p>\n<p style=\"margin: 1em 0px;\">\u8f93\u5165 123 \u7ed3\u679c\u5e94\u662f\u5b57\u7b26\u4e32 &#8216;123&#8217;\uff0c\u8bbf\u95ee toFixed \u65f6\u5b57\u7b26\u4e32\u6ca1\u6709\u8fd9\u4e2a\u65b9\u6cd5\u3002<\/p>\n<p style=\"margin: 1em 0px;\"><a href=\"https:\/\/ai.zhousir.top\/wp-content\/uploads\/2020\/04\/\u256c\u0432\u2568\u253c\u255c\u256a\u2550\u255d_20200401212049.png\" rel=\"fancybox\"><img decoding=\"async\" loading=\"lazy\" class=\"alignnone size-full wp-image-2545\" src=\"https:\/\/ai.zhousir.top\/wp-content\/uploads\/2020\/04\/\u256c\u0432\u2568\u253c\u255c\u256a\u2550\u255d_20200401212049.png\" alt=\"\u256c\u0432\u2568\u253c\u255c\u256a\u2550\u255d_20200401212049\" width=\"523\" height=\"127\"><\/a><\/p>\n<p style=\"margin: 1em 0px;\">\u8f93\u5165 &#8216;abc&#8217; \u5e94\u8fd4\u56de\u957f\u5ea6\u6570\u503c 3\uff0c\u518d\u8bbf\u95ee length\uff0c\u6570\u503c\u6ca1\u6709\u8be5\u5c5e\u6027\u3002<\/p>\n<p style=\"margin: 1em 0px;\"><a href=\"https:\/\/ai.zhousir.top\/wp-content\/uploads\/2020\/04\/\u256c\u0432\u2568\u253c\u255c\u256a\u2550\u255d_20200401212108.png\" rel=\"fancybox\"><img decoding=\"async\" loading=\"lazy\" class=\"alignnone size-full wp-image-2546\" src=\"https:\/\/ai.zhousir.top\/wp-content\/uploads\/2020\/04\/\u256c\u0432\u2568\u253c\u255c\u256a\u2550\u255d_20200401212108.png\" alt=\"\u256c\u0432\u2568\u253c\u255c\u256a\u2550\u255d_20200401212108\" width=\"564\" height=\"107\"><\/a><\/p>\n<p style=\"margin: 1em 0px;\">\u4f20\u5165\u5bf9\u8c61\u5219\u539f\u6837\u8fd4\u56de\uff0c\u7f16\u8bd1\u5668\u77e5\u9053 res \u662f { a: &#8216;a&#8217;, b: &#8216;b&#8217; }\uff0c\u8f93\u5165 res. \u540e VSCode \u4f1a\u5217\u51fa\u53ef\u8bbf\u95ee\u5c5e\u6027\u3002\u4e0d\u8981\u7528\u5176\u4ed6\u8bed\u8a00\u7684\u91cd\u8f7d\u601d\u7ef4\u6765\u8ba4\u8bc6 TS\u3002\u8bed\u6cd5\u7ec6\u8282\u540e\u9762\u4f1a\u7ec6\u8bb2\u3002<\/p>\n<p style=\"margin: 1em 0px;\">\u53e6\u5916\u8fd8\u6709\u642d\u6863 TSLint\uff0c\u548c ESLint \u7c7b\u4f3c\uff0c\u80fd\u7ea6\u675f\u548c\u63d0\u793a\u4ee3\u7801\uff0c\u56e2\u961f\u534f\u4f5c\u65f6\u8ba9\u591a\u4eba\u9075\u5faa\u540c\u4e00\u5957\u89c4\u8303\u2014\u2014\u5927\u5230\u8bed\u6cd5\uff0c\u5c0f\u5230\u6807\u70b9\u7a7a\u683c\u3002VSCode + TSLint + \u7c7b\u578b\u7cfb\u7edf\uff0c\u5199\u4ee3\u7801\u4f1a\u987a\u5f88\u591a\u3002<\/p>\n<h2 style=\"padding: 1px 12.5px; color: #ffffff; margin: 1.2em 0px 1em; border-radius: 4px; display: inline-block; background-color: #4870ac; font-size: 1.3em;\">\u56db\u3001\u53d1\u5c55\u8d8b\u52bf\uff1a\u4e3a\u4ec0\u4e48\u503c\u5f97\u5b66<\/h2>\n<p style=\"margin: 1em 0px;\">\u53ef\u80fd\u62c5\u5fc3 TS \u4f1a\u50cf CoffeeScript \u4e00\u6837\uff0c\u968f\u7740 ES \u66f4\u65b0\u9000\u51fa\u89c6\u7ebf\u3002\u5173\u952e\u5dee\u522b\u5728\u4e8e\u7c7b\u578b\u7cfb\u7edf\uff1aJS \u662f\u52a8\u6001\u811a\u672c\uff0cNode \u670d\u52a1\u751a\u81f3\u4e0d\u7528\u7f16\u8bd1\uff0c\u6539\u5b8c\u91cd\u542f\u5373\u53ef\uff0c\u8c03\u8bd5\u51e0\u4e4e\u90fd\u5728\u8fd0\u884c\u65f6\u3002\u8fd9\u4e2a\u7279\u70b9\u77ed\u671f\u5185\u4e0d\u4f1a\u53d8\u3002<\/p>\n<p style=\"margin: 1em 0px;\">TS \u80fd\u5728\u7f16\u5199\u65f6\u63d0\u793a\u9519\u8bef\uff0c\u4f7f\u7528\u67d0\u4e2a\u6570\u636e\u65f6\u5217\u51fa\u53ef\u8bbf\u95ee\u7684\u5c5e\u6027\u548c\u65b9\u6cd5\u3002\u9879\u76ee\u53d8\u5927\u3001\u591a\u4eba\u534f\u4f5c\u65f6\uff0c\u63a5\u53e3\u5b9a\u4e49\u548c\u65b9\u6cd5\u7528\u6cd5\u5bb9\u6613\u56e0\u4e60\u60ef\u6216\u6c9f\u901a\u4ea7\u751f\u5dee\u5f02\u3002\u5f15\u5165 TS \u540e\u4f1a\u5bf9\u5b9e\u73b0\u505a\u5f3a\u6821\u9a8c\uff0c\u4e0d\u6309\u63a5\u53e3\u5b9e\u73b0\u5c31\u7f16\u8bd1\u4e0d\u8fc7\uff1b\u8981\u6c42\u66f4\u9ad8\u53ef\u4ee5\u628a\u4e25\u683c\u68c0\u67e5\u5168\u90e8\u6253\u5f00\u3002<\/p>\n<p style=\"margin: 1em 0px;\">\u6bd4\u8f83\u9002\u5408 TS \u7684\u9879\u76ee\uff1a<\/p>\n<ul style=\"padding-left: 1rem; margin-left: 1rem; font-size: 0.9rem; list-style-type: disc;\">\n<li>\n<section>\u9700\u8981\u591a\u4eba\u5408\u4f5c\u5f00\u53d1\u7684\u9879\u76ee<\/section>\n<\/li>\n<li>\n<section>\u5f00\u6e90\u9879\u76ee\uff0c\u5c24\u5176\u662f\u5de5\u5177\u51fd\u6570\u6216\u7ec4\u4ef6\u5e93<\/section>\n<\/li>\n<li>\n<section>\u5bf9\u4ee3\u7801\u8d28\u91cf\u8981\u6c42\u5f88\u9ad8\u7684\u9879\u76ee<\/section>\n<\/li>\n<\/ul>\n<p style=\"margin: 1em 0px;\">\u5e7f\u4e3a\u4eba\u77e5\u7684\u4f8b\u5b50\uff1a<\/p>\n<ul style=\"padding-left: 1rem; margin-left: 1rem; font-size: 0.9rem; list-style-type: disc;\">\n<li>\n<section><a href=\"https:\/\/github.com\/Microsoft\/vscode\">VSCode<\/a>\uff1a\u5f00\u6e90\u7f16\u8f91\u5668\u672c\u8eab\u7528 TS \u5199\uff0c\u5929\u751f\u652f\u6301 TS<\/section>\n<\/li>\n<li>\n<section>Angular\u3001React\u3001Vue3.0\uff1a\u4e09\u8db3\u9f0e\u7acb\u7684\u6846\u67b6\u91cc\uff0cAngular \u548c React \u5df2\u7528 TS\uff1b\u4e13\u680f\u5199\u4f5c\u65f6 Vue3.0 \u4e5f\u5728\u7528 TS \u91cd\u6784\u3002\u7528 TS \u5f00\u53d1\u80fd\u5f97\u5230\u66f4\u597d\u7684\u7c7b\u578b\u652f\u6301\uff0c\u5f53\u7136\u4ecd\u53ef\u7528 JS<\/section>\n<\/li>\n<li>\n<section><a href=\"https:\/\/ant.design\/index-cn\">Ant Design<\/a>\uff1a\u8682\u8681\u91d1\u670d\u5f00\u6e90\u7684 React UI \u5e93\u7528 TS \u7f16\u5199\uff1b\u4e5f\u6709 Vue \u7248\uff0c\u98ce\u683c\u529f\u80fd\u4e00\u81f4\uff0c\u5bf9 TS \u652f\u6301\u540c\u6837\u597d<\/section>\n<\/li>\n<\/ul>\n<p style=\"margin: 1em 0px;\">TS \u5728\u5b9e\u73b0\u65b0\u7279\u6027\u65f6\u5bf9\u9f50 ES\u3002\u6807\u51c6\u8fd8\u6ca1\u5b9a\u7684\u5185\u5bb9\uff0c\u5b83\u53ef\u80fd\u5df2\u7387\u5148\u652f\u6301\uff0c\u4f8b\u5982\u7c7b\u7684\u79c1\u6709\u5c5e\u6027\u548c\u65b9\u6cd5\u3002ES6 \u7c7b\u6ca1\u6709\u79c1\u6709\u5c5e\u6027\u6982\u5ff5\uff0c\u8981\u5b9e\u73b0\u5f97 hack\uff08\u53ef\u53c2\u8003<a href=\"http:\/\/es6.ruanyifeng.com\/#docs\/class#%E7%A7%81%E6%9C%89%E6%96%B9%E6%B3%95%E5%92%8C%E7%A7%81%E6%9C%89%E5%B1%9E%E6%80%A7\">\u300aECMAScript 6 \u5165\u95e8\u300b- \u79c1\u6709\u65b9\u6cd5\u548c\u79c1\u6709\u5c5e\u6027<\/a>\uff09\uff1bTS \u53ef\u76f4\u63a5\u7528 <code style=\"font-family: Menlo, Monaco, Consolas, 'Liberation Mono', 'Roboto Mono', 'Courier New', 'Microsoft YaHei', monospace; color: #4870ac; font-size: 0.9em; font-weight: normal; overflow-wrap: break-word; padding: 2px 4px; border-radius: 3px; margin: 2px; background-color: #f6f8fa; word-break: break-all;\">private<\/code>\u3002ECMAScript \u65b0\u63d0\u6848\u7528 <code style=\"font-family: Menlo, Monaco, Consolas, 'Liberation Mono', 'Roboto Mono', 'Courier New', 'Microsoft YaHei', monospace; color: #4870ac; font-size: 0.9em; font-weight: normal; overflow-wrap: break-word; padding: 2px 4px; border-radius: 3px; margin: 2px; background-color: #f6f8fa; word-break: break-all;\">#<\/code> \u6807\u8bb0\u79c1\u6709\u5c5e\u6027\uff0c\u5f53\u65f6\u8fd8\u6ca1\u6709\u7f16\u8bd1\u5668\u652f\u6301\u8fd9\u79cd\u8bed\u6cd5\u3002<\/p>\n<p style=\"margin: 1em 0px;\">\u4ee5\u4e0a\u4fbf\u662f\u5bf9 TypeScript \u7684\u5927\u81f4\u4ecb\u7ecd\u3002<a href=\"https:\/\/www.imooc.com\/read\/35\/article\/338\">\u539f\u6587<\/a><\/p>\n<blockquote style=\"display: block; font-size: 0.9em; border-left: 3px solid #4870ac; padding: 0.5em 1em; margin: 0px; background: #f6f8fa; color: #40464f;\">\n<p style=\"margin: 1em 0px;\"><strong style=\"color: #4870ac;\">\u4e00\u53e5\u8bdd\u603b\u7ed3\uff1aTypeScript \u662f\u5e26\u7c7b\u578b\u7cfb\u7edf\u7684 JavaScript \u8d85\u96c6\uff1a\u4e0d\u66ff\u4ee3 JS\uff0c\u4f46\u80fd\u5728\u7f16\u5199\u671f\u62e6\u4f4f\u4e00\u6279\u53ea\u6709\u8fd0\u884c\u65f6\u624d\u4f1a\u7206\u7684\u9519\u3002<\/strong><\/p>\n<\/blockquote>\n<\/section>\n","protected":false},"excerpt":{"rendered":"<p>\u5b66 TypeScript \u662f\u4e0d\u662f\u5c31\u4e0d\u7528\u5b66 JavaScript \u4e86\uff1fVue 3.0 \u7528 TS \u91cd\u5199\u4e4b\u540e\u662f\u4e0d\u662f\u4e0d [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":[],"categories":[109,105],"tags":[150,204],"_links":{"self":[{"href":"https:\/\/ai.zhousir.top\/index.php?rest_route=\/wp\/v2\/posts\/2540"}],"collection":[{"href":"https:\/\/ai.zhousir.top\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/ai.zhousir.top\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/ai.zhousir.top\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/ai.zhousir.top\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=2540"}],"version-history":[{"count":3,"href":"https:\/\/ai.zhousir.top\/index.php?rest_route=\/wp\/v2\/posts\/2540\/revisions"}],"predecessor-version":[{"id":3687,"href":"https:\/\/ai.zhousir.top\/index.php?rest_route=\/wp\/v2\/posts\/2540\/revisions\/3687"}],"wp:attachment":[{"href":"https:\/\/ai.zhousir.top\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=2540"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/ai.zhousir.top\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=2540"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/ai.zhousir.top\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=2540"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}