小编Har*_*ika的帖子

如何修复 TypeScript 和 React 中禁止的非空断言?

我有如下代码:

type ItemProps = {
    status?: string;
}

<Items status={status!} /> // error here: warning  Forbidden non-null assertion
                           //                   @typescript-eslint/no-non-null-
Run Code Online (Sandbox Code Playgroud)

断言

我收到禁止的非空断言错误。

我该如何修复这个错误?

我努力了

<Items status={status && status}/>
Run Code Online (Sandbox Code Playgroud)

但这似乎不正确。

typescript reactjs

9
推荐指数
1
解决办法
5万
查看次数

标签 统计

reactjs ×1

typescript ×1