TypeScript名词解释系列:tsconfg中的target,module和moduleResolution
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的更多相关文章
- aop中的名词解释
aop中的名词解释 aop spring Joinpoint(连接点) 目标对象中所有可以增强的方法叫做连接点 Pointcut(切入点) 目标对象中要增强的的方法 Advice(通知/增强) 增强的 ...
- 转OSGchina中,array老大的名词解释
转OSGchina中,array老大的名词解释 转自:http://ydwcowboy.blog.163.com/blog/static/25849015200983518395/ osg:: Cle ...
- Lucene/ElasticSearch 学习系列 (2) Information Retrival 初步之名词解释
计算机领域一半是理论,一半是在理论基础之上的应用.要想深入地掌握某个方面的应用,就需要先学习那方面的理论. “搜索”是应用,其背后的理论是 "Information Retrieval&qu ...
- Android中的动画具体解释系列【4】——Activity之间切换动画
前面介绍了Android中的逐帧动画和补间动画,并实现了简单的自己定义动画.这一篇我们来看看怎样将Android中的动画运用到实际开发中的一个场景--Activity之间跳转动画. 一.定义动画资源 ...
- 面试系列-面试官:你能给我解释一下javascript中的this吗?
一.前言 关于javascript中的this对象,可能已经被大家说烂了. 即使是这样,我依然决定将这篇文章给水出来.毕竟全国在新型肺炎的影响下,公司没法正常复工. 除了刷刷手机,还是要适当的学习一下 ...
- css名词解释
<!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8&quo ...
- b2c项目基础架构分析(二)前端框架 以及补漏的第一篇名词解释
继续上篇,上篇里忘记了也很重要的前端部分,今天的网站基本上是以一个启示页,然后少量的整页切换,大量的浏览器后台调用web服务局部.动态更新页面显示状态这种方式在运作的,从若干年前简单的ajax流行起来 ...
- b2c项目基础架构分析(一)b2c 大型站点方案简述 已补充名词解释
我最近一直在找适合将来用于公司大型bs,b2b b2c的基础架构. 实际情况是要建立一个bs架构b2b.b2c的网站,当然还包括wap站点.手机app站点. 一.现有公司技术人员现状: 1.熟悉asp ...
- maven名词解释
Maven名词解释 Project:任何你想build的事物,Maven都可以认为它们是工程.这些工程被定义为工程对象模型(POM,Poject Object Model).一个工程可以依赖其它的工程 ...
- Highcharts基本名词解释
1.Highcharts基本组成: 2.名词解释 lang 语言文字对象 所有Highcharts文字相关的设置 chart 图表 图表区.图形区和通用图表配置选项 colors 颜色 图表数据列颜色 ...
随机推荐
- 安装 Google Cloud CLI(gcloud)
安装 Ubuntu # 更新软件包索引 sudo apt update # 安装辅助工具 sudo apt install apt-transport-https ca-certificates gn ...
- 【DVWA】安全测试工具之BurpSuite
一.应用场景 二.安装软件 官网下载地址:https://portswigger.net/burp/releases 下载版本2021.7 注册机的 Github 项目地址:TrojanAZhen/B ...
- LaViT:这也行,微软提出直接用上一层的注意力权重生成当前层的注意力权重 | CVPR 2024
Less-Attention Vision Transformer利用了在多头自注意力(MHSA)块中计算的依赖关系,通过重复使用先前MSA块的注意力来绕过注意力计算,还额外增加了一个简单的保持对角性 ...
- AI图像放大工具,图片放大无所不能
AI图像放大工具,如ESRGAN,对于提高由Stable Diffusion生成的AI图像质量至关重要.它们被广泛使用,以至于许多Stable Diffusion的图形用户界面(GUI)都内置了支持. ...
- containerd 拉取k8s.gcr.io/pause镜像i/o timeout
由于k8s.gcr.io 需要连外网才可以拉取到,导致 k8s 的基础容器 pause 经常无法获取.k8s docker 可使用代理服拉取,再利用 docker tag 解决问题 docker pu ...
- LinkedHashMap原理详解—从LRU缓存机制说起
写在前面 从一道Leetcode题目说起 首先,来看一下Leetcode里面的一道经典题目:146.LRU缓存机制,题目描述如下: 请你设计并实现一个满足 LRU (最近最少使用) 缓存 约束的数据结 ...
- 深度学习批次(batch)、迭代(iteration)、周期(epoch)、前向传播(forward propagation)、反向传播(backward propagation)、学习率(learning rate)概念解释
虽然现在应该是已经熟练掌握这些基础概念的时候,但是我是鱼的记忆,上一秒的事情,下一秒就忘了,除非是重要的人的重要的事情,呜呜呜呜,我这个破脑子. 还是写一下吧,直接GPT出来的(人类之光,欢呼~). ...
- RxJS 系列 – Transformation Operators
前言 前几篇介绍过了 Creation Operators Filter Operators Join Creation Operators Error Handling Operators 这篇继续 ...
- schedtune.colocatte的作用
schedtune.colocate 参数主要通过 /proc/sys/kernel/schedtune.colocate 接口进行配置.具体的使用方式和可选参数如下: 使用方法 你可以通过以下命令来 ...
- Diffusion系列-预备知识I -(一)
预备知识 范数 范数是一种函数,用来度量向量的大小1.在机器学习.信号处理等领域中,范数常常被用作正则化方法,通过对参数向量的范数进行约束,达到控制模型复杂度.防止过拟合等目的.常见的范数有0范数.1 ...