Property 'config' has no initializer and is not definitely assigned in the constructor.ts(


最近在使用 typescript 写项目,然后报了下面的警告

 

Property 'config' has no initializer and is not definitely assigned in the constructor.ts(2564) 解决办法:

1.tsconfig.json配置以下设置,简单粗暴,但是超级不推荐。

{
  "compilerOptions": {
    // 严格属性初始化
    "strictPropertyInitialization": false
  }
}

2. 使用断言 !

 3.使用可选属性 ?

 4. 使用联合类型

Object | undefined | null;