以下是您可能在控制台中看到的常见错误列表以及如何修复它们。
如果您在控制台中看到此错误:
Warning: A component is changing an uncontrolled input to be controlled. This is likely caused by the value changing from undefined to a defined value, which should not happen. Decide between using a controlled or uncontrolled input element for the lifetime of the component. More info: https://reactjs.org/link/controlled-components
Warning: A component is changing an uncontrolled input to be controlled. This is likely caused by the value changing from undefined to a defined value, which should not happen. Decide between using a controlled or uncontrolled input element for the lifetime of the component. More info: https://reactjs.org/link/controlled-components
很可能您在 useForm Hook 或 form.Field 组件使用中忘记了 defaultValues。这种情况发生是因为输入在表单值初始化之前被渲染,因此在进行文本输入时从 undefined 变为 ""。
如果您正在使用 form.Field 并且在检查 field.state.value 的值时,您看到字段的值类型为 unknown,很可能是您的表单类型太大,我们无法安全地评估。
这通常表明您应该将表单分解为更小的表单或为您的表单使用更具体的类型。
解决此问题的方法是使用 TypeScript 的 as 关键字转换 field.state.value:
const value = field.state.value as string
const value = field.state.value as string
如果您在运行 tsc 时在控制台中看到此错误:
Type instantiation is excessively deep and possibly infinite
Type instantiation is excessively deep and possibly infinite
��遇到了我们在类型定义中没有捕获的错误。虽然我们已经尽力确保我们的类型尽可能准确,但在某些边缘情况下,TypeScript 在处理我们类型的复杂性时遇到了困难。
请在 GitHub 上向我们报告此问题,以便我们可以修复它。只需确保包含最小的重现,以便我们能够帮助您调试。
请记住,这是一个 TypeScript 错误,而不是运行时错误。这意味着您的代码仍将在用户的机器上按预期运行。