tsconfg中的target,module和moduleResolution

target

就是TypeScript文件编译后生成的javascript文件里的语法应该遵循哪个JavaScript的版本。可选项为:"ES5", "ES6""ES2015", "ES2016", "ES2017"或 "ESNext"

module

就是你的TypeScript文件中的module,采用何种方式实现,可选项为:"None", "CommonJS", "AMD", "System", "UMD", "ES6"或 "ES2015"。具体每一个module的定义,请参考链接:

https://medium.com/computed-comparisons/commonjs-vs-amd-vs-requirejs-vs-es6-modules-2e814b114a0b

moduleResolution

就是告诉TypeScript编译器,采用何种方式解析(也就是查找)TypeScript文件中依赖的模块的位置,可选项为:Classic和Node,具体定义,请参考链接:

https://www.tslang.cn/docs/handbook/module-resolution.html

target举例

ts文件中的源代码

1 async function helloWorld(): Promise<string> {
2 const res = await fetch('/static/data.json');
3 const txt = await res.text();
4 return txt;
5 }
6 (async ()=>{
7 const txt = await helloWorld()
8 console.log(`async func: `, txt)
9 })()

target设置成es5

 1 var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
2 function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
3 return new (P || (P = Promise))(function (resolve, reject) {
4 function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
5 function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
6 function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
7 step((generator = generator.apply(thisArg, _arguments || [])).next());
8 });
9 };
10 var __generator = (this && this.__generator) || function (thisArg, body) {
11 var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g;
12 return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
13 function verb(n) { return function (v) { return step([n, v]); }; }
14 function step(op) {
15 if (f) throw new TypeError("Generator is already executing.");
16 while (_) try {
17 if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t;
18 if (y = 0, t) op = [op[0] & 2, t.value];
19 switch (op[0]) {
20 case 0: case 1: t = op; break;
21 case 4: _.label++; return { value: op[1], done: false };
22 case 5: _.label++; y = op[1]; op = [0]; continue;
23 case 7: op = _.ops.pop(); _.trys.pop(); continue;
24 default:
25 if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
26 if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
27 if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
28 if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
29 if (t[2]) _.ops.pop();
30 _.trys.pop(); continue;
31 }
32 op = body.call(thisArg, _);
33 } catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
34 if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
35 }
36 };
37 var _this = this;
38 function helloWorld() {
39 return __awaiter(this, void 0, void 0, function () {
40 var res, txt;
41 return __generator(this, function (_a) {
42 switch (_a.label) {
43 case 0: return [4 /*yield*/, fetch('/static/data.json')];
44 case 1:
45 res = _a.sent();
46 return [4 /*yield*/, res.text()];
47 case 2:
48 txt = _a.sent();
49 return [2 /*return*/, txt];
50 }
51 });
52 });
53 }
54 (function () { return __awaiter(_this, void 0, void 0, function () {
55 var txt;
56 return __generator(this, function (_a) {
57 switch (_a.label) {
58 case 0: return [4 /*yield*/, helloWorld()];
59 case 1:
60 txt = _a.sent();
61 console.log("async func: ", txt);
62 return [2 /*return*/];
63 }
64 });
65 }); })();

target设置成es6

 1 var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
2 function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
3 return new (P || (P = Promise))(function (resolve, reject) {
4 function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
5 function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
6 function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
7 step((generator = generator.apply(thisArg, _arguments || [])).next());
8 });
9 };
10 function helloWorld() {
11 return __awaiter(this, void 0, void 0, function* () {
12 const res = yield fetch('/static/data.json');
13 const txt = yield res.text();
14 return txt;
15 });
16 }
17 (() => __awaiter(this, void 0, void 0, function* () {
18 const txt = yield helloWorld();
19 console.log(`async func: `, txt);
20 }))();

target设置成esnext

async function helloWorld() {
const res = await fetch('/static/data.json');
const txt = await res.text();
return txt;
}
(async () => {
const txt = await helloWorld();
console.log(`async func: `, txt);
})();

module举例

ts文件中的源代码

设置为commonjs

设置为es6

TypeScript名词解释系列:tsconfg中的target,module和moduleResolution的更多相关文章

  1. aop中的名词解释

    aop中的名词解释 aop spring Joinpoint(连接点) 目标对象中所有可以增强的方法叫做连接点 Pointcut(切入点) 目标对象中要增强的的方法 Advice(通知/增强) 增强的 ...

  2. 转OSGchina中,array老大的名词解释

    转OSGchina中,array老大的名词解释 转自:http://ydwcowboy.blog.163.com/blog/static/25849015200983518395/ osg:: Cle ...

  3. Lucene/ElasticSearch 学习系列 (2) Information Retrival 初步之名词解释

    计算机领域一半是理论,一半是在理论基础之上的应用.要想深入地掌握某个方面的应用,就需要先学习那方面的理论. “搜索”是应用,其背后的理论是 "Information Retrieval&qu ...

  4. Android中的动画具体解释系列【4】——Activity之间切换动画

    前面介绍了Android中的逐帧动画和补间动画,并实现了简单的自己定义动画.这一篇我们来看看怎样将Android中的动画运用到实际开发中的一个场景--Activity之间跳转动画. 一.定义动画资源 ...

  5. 面试系列-面试官:你能给我解释一下javascript中的this吗?

    一.前言 关于javascript中的this对象,可能已经被大家说烂了. 即使是这样,我依然决定将这篇文章给水出来.毕竟全国在新型肺炎的影响下,公司没法正常复工. 除了刷刷手机,还是要适当的学习一下 ...

  6. css名词解释

    <!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8&quo ...

  7. b2c项目基础架构分析(二)前端框架 以及补漏的第一篇名词解释

    继续上篇,上篇里忘记了也很重要的前端部分,今天的网站基本上是以一个启示页,然后少量的整页切换,大量的浏览器后台调用web服务局部.动态更新页面显示状态这种方式在运作的,从若干年前简单的ajax流行起来 ...

  8. b2c项目基础架构分析(一)b2c 大型站点方案简述 已补充名词解释

    我最近一直在找适合将来用于公司大型bs,b2b b2c的基础架构. 实际情况是要建立一个bs架构b2b.b2c的网站,当然还包括wap站点.手机app站点. 一.现有公司技术人员现状: 1.熟悉asp ...

  9. maven名词解释

    Maven名词解释 Project:任何你想build的事物,Maven都可以认为它们是工程.这些工程被定义为工程对象模型(POM,Poject Object Model).一个工程可以依赖其它的工程 ...

  10. Highcharts基本名词解释

    1.Highcharts基本组成: 2.名词解释 lang 语言文字对象 所有Highcharts文字相关的设置 chart 图表 图表区.图形区和通用图表配置选项 colors 颜色 图表数据列颜色 ...

随机推荐

  1. Gluon 编译 JavaFx -> exe

    Gluon 编译 JavaFx -> exe 能力强的伙伴可以直接参考官方文档 开发工具 idea 2023.3 idea gluon plugin git apache-maven-3.8.4 ...

  2. MYSQL数据库备份还原,并还原到最新状态(mysqldump)

    启用二进制日志文件 vim /etc/my.cnf 配置文件位置及文件名根据实际情况确定<br>sql_log_bin=on|off:是否记录二进制日志,默认为on 在需要的时候设置为of ...

  3. 深入理解c语言指针与内存

    一.将int强制转换为int指针,将int指针强转换为int void f(void) { int *p = (int*)100; //将int强制转换为int指针 printf("%d\n ...

  4. JavaScript – Set and Map

    参考 Set 和 Map 数据结构 Set 介绍和使用 Set 很像 Array, 但其实它是一个 Iteralbe 对象. 用于保存多个值, 而且具有 unique 特性 (1 个 set 里面不会 ...

  5. JavaScript – Modular

    前言 我几乎闪过了那几年的 Modular 混乱时代. CommonJS 火的时候, 我没有用 Node.js AMD, CMD 火的时候, 我的项目还小, 加上用了 AngularJS 自带模块功能 ...

  6. mono 下运行 VB.NET 编写的 WinForm 程序

    操作系统环境 UOS  20 安装 Mono 可以参考 dotnet 在 UOS 国产系统上安装 Mono 开发工具的方法 要点如下 nano /etc/apt/sources.list 增加一行 D ...

  7. Windows下使用Wireshark分析USB通信

    WireShark中对USB数据捕获 可以监视与主机连接的usb数据. usb设备是三段地址描述,例如1.15.1,第一个是总线,第二个是设备地址,第三个是端口. USB数据抓包分析 这些是鼠标的数据 ...

  8. Android Systrace 基础知识 -- Systrace 简介

    1. 正文 Systrace 是 Android4.1 中新增的性能数据采样和分析工具.它可帮助开发者收集 Android 关键子系统(如 SurfaceFlinger/SystemServer/Ke ...

  9. LinearRegression线性回归

    1.LinearRegression将方程分为两个部分存放,coef_存放回归系数,intercept_则存放截距,因此要查看方程,就是查看这两个变量的取值. 2.回归系数(regression co ...

  10. Java实用小工具系列1---使用StringUtils分割字符串

    经常有这种情况,需要将逗号分割的字符串,比如:aaa, bbb ,ccc,但往往是人工输入的,难免会有多空格逗号情况,比如:aaa, bbb , ccc, ,,这种情况使用split会解析出不正常的结 ...