TypeScript is very particular about what is and isn't allowed in a TS file to protect you from common developer errors. By default if you set the compile target to ES5 it only allows you to use globally defined variables that were available in the ES5 time-frame. That said it is super easy to configure TypeScript to use ES6 or ESNext using the liboption.

We also cover how to make sure that these features work across the widest range of browsers using a simple polyfill.

Sometime, you use "Promise", typescript reports error that Cannot find defination for Promise.

To solve this problem, you can change in tsconfig.json:

{
"compilerOptions": {
"target": "es5",
"outDir": "lib",
"lib": [
"dom",
"es2017"
]
},
"include": [
"src"
]
}

Add a "lib" tag, and add "es2017" or "es6" into the array. This can help to solve the "Promise" (or any features not existing in es5).

Second way to do it is polyfill.

Install:

npm i -D core-js

In your code, just import 'shim' from 'core-js':

import "core-js/shim";
const foo = () => Promise.resolve(null);

[TypeScript] Using ES6 and ESNext with TypeScript的更多相关文章

  1. ES6 中 Class 与 TypeScript 中 Class 的区别(待补充)

    ES6 中 Class 与 TypeScript 中 Class 的区别(待补充)

  2. JavaScript、TypeScript、ES6三者之间的联系和区别

    ES6是什么 ECMAScript 6.0(以下简称ES6)是JavaScript语言(现在是遵循ES5标准)的下一代标准,已经在2015年6月正式发布了.它的目标,是使得JavaScript语言可以 ...

  3. electron教程(番外篇二): 使用TypeScript版本的electron, VSCode调试TypeScript, TS版本的ESLint

    我的electron教程系列 electron教程(一): electron的安装和项目的创建 electron教程(番外篇一): 开发环境及插件, VSCode调试, ESLint + Google ...

  4. 玩转TypeScript(引言&文章目录) --初看TypeScript.

    JavaScript过去一直被当作一种玩具语言存在,直到2005年以后,这门语言又开始活跃并可以说是火爆,而且随着浏览器版本的不断升级和完善,各种DOM之间的兼容性已经渐渐的被各种技术解决了,比如经典 ...

  5. TypeScript 与 es6 写法的区别

    import 方式 ts 默认对于 commonjs 的模块是这样加载的:import * as React from 'react'; es6:import React from 'react'; ...

  6. TypeScript完全解读(26课时)_2.TypeScript完全解读-基础类型

    2.TypeScript完全解读-基础类型 src下新建example文件夹并新建文件.basic-type.ts.截图中单词拼错了.后需注意一下是basic-type.ts 可以装tslint的插件 ...

  7. TypeScript完全解读(26课时)_4.TypeScript完全解读-接口

    4.TypeScript完全解读-接口 初始化tslint tslint --init:初始化完成后会生成tslint.json的文件 如果我们涉及到一些规则都会在这个rules里面进行配置 安装ts ...

  8. TypeScript完全解读(26课时)_5.TypeScript完全解读-函数

    5.TypeScript完全解读-函数 新建function.ts.然后在index.ts内引用 给函数定义参数类型:上面是es5的写法 下面是ts6的写法 一个完整的函数类型.括号 箭头 numbe ...

  9. TypeScript完全解读(26课时)_9.TypeScript完全解读-TS中的类

    9.TypeScript完全解读-TS中的类 创建class.ts文件,并在index.ts内引用 创建一个类,这个类在创建好后有好几个地方都标红了 这是tslint的一些验证规则 一保存就会自动修复 ...

随机推荐

  1. 【Java】Java Socket 通信演示样例

    用socket(套接字)实现client与服务端的通信. 这里举两个样例: 第一种是每次client发送一个数据,服务端就做一个应答. (也就是要轮流发) 另外一种是client能够连续的向服务端发数 ...

  2. android屏幕适配方案

    曾经看了android的屏幕适配方案,有非常多种.当中自己用到的一种是:先找一款主流的分辨率的android机,如:1080*1920的分辨率做基准,然后在这个基准上.调整好一切布局.图片.适配其它手 ...

  3. php线性表数组实现的删除操作

    php线性表数组实现的删除操作 一.总结 1.array_pop(): 函数删除数组中的最后一个元素. 二.代码 代码一: //线性表的删除(数组实现) function delete_array_e ...

  4. 1.一个WEB应用的开发流程

    先说项目开发过程中团队人员的分工协作. 一.人员安排 毕业至今的大部分项目都是独立完成,虽然也有和其他同事协作的时候,但自认为对团队协作的了解和认知都还有所欠缺.很清楚团队协作的重要性,但尚未有很好的 ...

  5. js日期常用方法

    js获取日期时间格式 export function formatDateTime(timeStamp) { var date = new Date(); date.setTime(timeStamp ...

  6. HTML中input标签maxlength属性的妙处

    HTML中的input标签可是很常用的. HTML本身也非常简单,就是若干标签,每个标签有若干属性. 我在学习HTML的过程中,也没有太过重视. 今年,在写前端表单验证的时候,发现maxlength这 ...

  7. 图像处理 Mine

    1)中值滤波:排序取中间值.作用:去噪点 1.1)均值滤波; 1.2)高斯模糊:执行高斯模糊,然后改混合模式,改成叠加.柔光或者深色.就能得到平滑而不模糊的效果. 2)腐蚀.膨胀:开运算(腐蚀后膨胀) ...

  8. 【Codeforces Round #447 (Div. 2) C】Marco and GCD Sequence

    [链接] 我是链接,点我呀:) [题意] 在这里输入题意 [题解] 把gcd(a[1..n])放在输入的n个数之间. [代码] /* 1.Shoud it use long long ? 2.Have ...

  9. [React] Configure a React & Redux Application For Production Deployment and Deploy to Now

    In this lesson, we’ll make a few small changes to our scripts and add some environment variables tha ...

  10. Garbage Collection Optimization for High-Throughput and Low-Latency Java Applications--转载

    原文地址:https://engineering.linkedin.com/garbage-collection/garbage-collection-optimization-high-throug ...