TypeScript Errors All In One

1. Property 'name' has no initializer and is not definitely assigned in the constructor.ts

属性"名称"没有初始化程序,并且在构造函数中未明确分配

Strict Class Initialization

--strictPropertyInitialization

https://www.typescriptlang.org/docs/handbook/release-notes/typescript-2-7.html#strict-class-initialization

class C {
foo: number;
bar = "hello";
baz: boolean;
// Property 'baz' has no initializer and is not definitely assigned in the constructor.ts(2564)
constructor() {
this.foo = 42;
}
}

solutions

class CC {
foo: number;
bar = "hello";
baz: boolean | undefined;
constructor() {
this.foo = 42;
}
}

  1. tsconfig.json 关闭 Strict Class Initialization

tsconfig.json

{
"include": ["src/**/*"],
"exclude": ["tests/**/*"],
"compilerOptions": {
"target": "es5",
"module": "commonjs",
"jsx": "preserve",
"declaration": false,
"declarationMap": false,
"sourceMap": true,
"outDir": "./build",
"rootDir": "./",
"removeComments": true,
"downlevelIteration": true,
"isolatedModules": false,
"strict": true,
"noImplicitAny": true,
"strictNullChecks": true,
"strictFunctionTypes": true,
"strictPropertyInitialization": false,// 关闭
"noImplicitThis": true,
"alwaysStrict": true,
"noUnusedLocals": true,
"noUnusedParameters": true,
"noImplicitReturns": true,
"noFallthroughCasesInSwitch": true,
"moduleResolution": "node",
"esModuleInterop": true,
"allowUmdGlobalAccess": true,
"experimentalDecorators": true,
"emitDecoratorMetadata": true,
"skipLibCheck": true,
"forceConsistentCasingInFileNames": true
}
}

2. declaration for the 'Promise' constructor or include 'ES2015' in your --lib option

interface Promise Represents the completion of an asynchronous operation

An async function or method in ES5/ES3 requires the 'Promise' constructor.

Make sure you have a declaration for the 'Promise' constructor or include 'ES2015' in your --lib option.ts(2705)


const getRequestTo = async <R>(endpoint: string): Promise<ApiResponseInterface<R>> => {
const request = await fetch(process.env.HOST + endpoint);
const response = await request.json();
return response;
}; const userResponse = getRequestTo('/user-data');

solution, How to fixed TypeScript Promise Error

just need to add a line of code"lib": ["es2015"], in your tsconfig.json

{
// ...
"compilerOptions": {
"target": "es5",
"module": "commonjs",
"lib": ["es2015"],//
// ...
}
}

Cannot find name 'fetch'.ts(2304)

solution, How to fixed TypeScript fetch Error

just need to add a line of code"lib": ["DOM"], in your tsconfig.json

{
// ...
"compilerOptions": {
"target": "es5",
"module": "commonjs",
"lib": ["es2015", "DOM"],//
// ...
}
}

refs

https://stackoverflow.com/questions/49699067/property-has-no-initializer-and-is-not-definitely-assigned-in-the-construc

https://stackoverflow.com/questions/54104187/typescript-complain-has-no-initializer-and-is-not-definitely-assigned-in-the-co/54104796



xgqfrms 2012-2020

www.cnblogs.com 发布文章使用:只允许注册用户才可以访问!


TypeScript Errors All In One的更多相关文章

  1. 【前端】Vue2全家桶案例《看漫画》之七、webpack插件开发——自动替换服务器API-URL

    转载请注明出处:http://www.cnblogs.com/shamoyuu/p/vue_vux_app_7.html 项目github地址:https://github.com/shamoyuu/ ...

  2. 【前端】Vue和Vux开发WebApp日志二、优化gulp任务

    转载请注明出处:http://www.cnblogs.com/shamoyuu/p/vue_vux_2.html 项目github地址:https://github.com/shamoyuu/vue- ...

  3. 【前端】Vue和Vux开发WebApp日志一、整合vue+cordova和webpack+gulp

    转载请注明出处:http://www.cnblogs.com/shamoyuu/p/vue_vux.html 项目github地址:https://github.com/shamoyuu/vue-vu ...

  4. vue-cli中webpack配置详解

    vue-cli是构建vue单页应用的脚手架,命令行输入vue init <template-name> <project-name>从而自动生成的项目模板,比较常用的模板有we ...

  5. vue-cli脚手架中webpack配置基础文件详解

    一.前言 原文:https://segmentfault.com/a/1190000014804826 vue-cli是构建vue单页应用的脚手架,输入一串指定的命令行从而自动生成vue.js+wep ...

  6. 学习一个Vue模板项目

    最开始学习Vue的时候,不建议直接使用模板,而应该自己从头写起.模板都是人写的,要坚信"人能我能".只有自己亲自实践,才能促进自己主动思考,才能对模板.框架有深刻的理解. 在Git ...

  7. Vue的配置

    一.build:打包的配置文件的文件夹 1.build.js  生产版本的配置文件,一般这个文件我们是不改的 'use strict' //调用检查版本的文件,check-versions的导出直接是 ...

  8. 为了记忆和方便翻阅 vue构建后的结构目录说明

    一. ├── build              // 项目构建(webpack)相关代码             记忆:(够贱)    9个 │ ├── build.js       // 生产环 ...

  9. vue-cli 脚手架中 webpack 配置基础文件详解

    一.前言 vue-cli是构建vue单页应用的脚手架,输入一串指定的命令行从而自动生成vue.js+wepack的项目模板.这其中webpack发挥了很大的作用,它使得我们的代码模块化,引入一些插件帮 ...

随机推荐

  1. Java 给Word不同页面设置不同背景

    Word文档中,可直接通过[设计]-[页面颜色]页面颜色,通过Java代码可参考如下设置方法: 1. 设置单一颜色背景 doc.getBackground().setType(BackgroundTy ...

  2. 简单监控liunx中cpu、内存、磁盘及发送邮件参考

    shell脚本 vim jk.sh  #命名脚本名   #!/bin/bash time=`date "+%Y-%m-%d %H:%M:%S"`      #定义时间 echo & ...

  3. 封装JSONP 函数,方便请求发送

    封装JSONP 函数,方便请求发送 封装jsonp的代码和封装Ajax的代码非常的相似!可以参照食用偶! <button id="btn">点击我发送请求!</b ...

  4. 用CSS制做一个三角形!

    用CSS制做一个三角形! <style> .outer { width: 0; height: 0; border-left: 10px solid transparent; border ...

  5. https://nginx.org/en/docs/http/request_processing.html

    https://nginx.org/en/docs/http/request_processing.html

  6. 本地MarkDown优雅发表

    本地MarkDown优雅发表 前言 身为一名程序员,记录笔记.发表博客首选便是MarkDown,现在网上有好多发表博客的地方:CSDN.博客园.简书,甚至一些大佬都有自己专属博客,但自己最喜欢的还是博 ...

  7. odoo-nginx 配置之80端口

    1 upstream odoo { 2 server 127.0.0.1:8069 weight=1 fail_timeout=0; 3 } 4 5 upstream odoo-im { 6 serv ...

  8. 日志框架(Log4J、SLF4J、Logback)--日志规范与实践

    文章目录 一.Log4j 1.1新建一个Java工程,导入Log4j包,pom文件中对应的配置代码如下: 1.2resources目录下创建log4j.properties文件. 1.3输出日志 1. ...

  9. 使用mybatis自动实现接口封装返回结果集

    import java.lang.annotation.Annotation; import java.lang.annotation.Documented; import java.lang.ann ...

  10. jmespath(1)基础语法

    前言 JMESPath是JSON的查询语言.您可以从JSON文档中提取和转换元素 官方文档:https://jmespath.org/tutorial.html 基本表达式 JMESPath用的最多的 ...