是否可以在没有 Typescript 抱怨的情况下解构来自函数调用的对象?
文件 1
- 反应组件 1
...
let obj = null // <-- object initialization
...
useEffect(() => {
obj = functionCall(...) // <-- function call that populates the object
}, [obj])
- 反应组件 2
const { key1, key2 } = obj // <-- object destructuring
在这里,我从 Typescript 收到以下抱怨
- 类型“null”上不存在属性“key1”。
- 类型“null”上不存在属性“key2”。
如何删除这些警告?