簡體   English   中英

“null”類型的賦值推斷為“any”

[英]Assignment of “null” type inferred as “any”

我看到 function 參數缺少類型錯誤報告:

private _toggle(updates: I_Type | null) {
  const should_toggle = this.thing && !updates.foo

  // ...
}

updates應該是I_Typenull類型。 但是,當不使用可選鏈接時, .updates.foo不會顯示類型錯誤。 即類型錯誤不應該只顯示?updates..foo是否有?. 操作員。

我不確定我是否誤解了什么,或者我的 eslint/tslint 配置錯誤。 .updates.foo不應該導致類型錯誤嗎?

更新

根據 VLAZ 的評論,解決方案是將strict添加到 tsconfig compilerOptions

根據 VLAZ 在問題中的評論,解決方案是將strict添加到 tsconfig compilerOptions

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM