输入类型的输入参数formik.error和formik.touched(prime react+ formik)
我正在使用TypeScript进行PrimeReAtct,现在我必须将Formik用作Formik form验证器。 primerereAtct(v7)formik文档: https://www.primeg/primeg/primeg/primeface.org/primefaces.org/primeface.orprimeface.org/primereact-v7, /#/formik 当您将选项卡切换到TS源时,没有任何更改。 我对部分有问题:
const isFormFieldValid = (name) => !!(formik.touched[name] && formik.errors[name]);
const getFormErrorMessage = (name) => {
return isFormFieldValid(name) && <small className="p-error">{formik.errors[name]}</small>;
};
我无法求解“名称”类型。我尝试了:string,formiktouched,任何formikerror ... 当我尝试将字符串作为参数类型时,我的IDE说:
ts7053:元素隐式具有“任何”类型,因为类型'string'的表达式不能用于索引类型'formikTouched&lt; {name:string; }&gt;'。 &nbsp;&nbsp; no索引签名,在类型“ formiktouched&lt; {name:string; string; }&gt;'。
有人可以帮我吗?
I am using PrimeReact with Typescript and now I have to use Formik as form validator.
PrimeReact(v7) Formik documentation: https://www.primefaces.org/primereact-v7/#/formik
and there are no changes when you switch the tab to TS source.
I have problem with part:
const isFormFieldValid = (name) => !!(formik.touched[name] && formik.errors[name]);
const getFormErrorMessage = (name) => {
return isFormFieldValid(name) && <small className="p-error">{formik.errors[name]}</small>;
};
I cannot solve the "name" type. I tried for a :string, FormikTouched, any, FormikError...
When I try string as type of parameter my IDE say:
TS7053: Element implicitly has an 'any' type because expression of type 'string' can't be used to index type 'FormikTouched<{ name: string; }>'. No index signature with a parameter of type 'string' was found on type 'FormikTouched<{ name: string; }>'.
Could someone help me with this please?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我这样做了:
打字稿停止抱怨,现在正在运行而没有错误。
I did this:
Typescript stops complaining and now is running without error.