输入'布尔值| undefined' 不能分配给类型 'boolean'.ts(2322)

时间:2021-06-04 11:30:15

标签: reactjs typescript material-ui formik

我发现有很多关于 stackover flow 的类似讨论,但我认为这与 Typescript 版本有关,因为我的代码在使用 typescript 4.2.4 时没有问题。

我的代码如下。

...
 const formik = useFormik({
    initialValues: {
      title: "",
      link: "",
      content: "",
      post_type: "",
    },
   ...
  });

  <TextField
    {...params}
    label="Post Type"
    variant="outlined"
    margin="normal"
    error={formik.touched.post_type && Boolean(formik.errors.post_type)} //on "error"props, I am having error notification on vscode
    helperText={formik.errors.post_type}
    inputProps={{
    ...params.inputProps,
    }}
  />

Screen shot of my error notification 即使它有错误通知,但代码有效。版本 4.2.4 的 Typescript 没有错误通知,但我在 4.4.0-dev 上收到此错误通知 我很想知道为什么我会遇到错误以及如何解决。

提前致谢。

0 个答案:

没有答案
相关问题