我有以下代码行:
const allGarments = teeMeasuresAverages || JSON.parse(localStorage.getItem("teeMeasuresAverages")) || teeMeasuresAveragesLocal;
typescript抛出此警告:
Argument of type 'string | null' is not assignable to parameter of type 'string'.
Type 'null' is not assignable to type 'string'.
所以我尝试包含非空断言运算符 (!):
const allGarments = teeMeasuresAverages || JSON.parse(localStorage.getItem("teeMeasuresAverages")) || teeMeasuresAveragesLocal;
然后给了我一个不同的警告:
Forbidden non-null assertion.
我是typescript的新手。它在这里寻找什么?