I am currently working on a project using Vue and TypeScript, and I am encountering an issue with returning a function while attempting to validate my form. Below are the errors I am facing:
Element implicitly has an 'any' type because expression of type 'string' can't be used to index type '{ name: ((v: string) => string | true)[]; enrollment: ((v?: string) => Fn)[]; cpf: ((number: string) => string | true)[]; profession: ((v: unknown) => Fn)[]; admission_date: ((v: unknown) => Fn)[]; department: ((v: unknown) => Fn)[]; email: ((v: unknown) => Fn)[]; phone: ((v: unknown) => Fn)[]; }'. No index signature with a parameter of type 'string' was found on type '{ name: ((v: string) => string | true)[]; enrollment: ((v?: string) => Fn)[]; cpf: ((number: string) => string | true)[]; profession: ((v: unknown) => Fn)[]; admission_date: ((v: unknown) => Fn)[]; department: ((v: unknown) => Fn)[]; email: ((v: unknown) => Fn)[]; phone: ((v: unknown) => Fn)[]; }'.
And
Unsafe return of an `any` typed value.eslint@typescript-eslint/no-unsafe-return
My code:
const myRules = {
name: [
isPersonName('', t),
],
enrollment: [
eqLength('', 4, t)
],
cpf: [
isValidCpf(t),
],
profession: [isRequired('', t)],
admission_date: [isRequired('', t)],
department: [isRequired('', t)],
email: [isRequired('', t)],
phone: [isRequired('', t)],
}
This is where the error occurs:
//@ts-ignore
const getMyRules = (item: string) => myRules[item]
I find it confusing that when I log the data in the console, everything appears correct, but when I try to return the value, ESLint throws an error.
//@ts-ignore
const getMyRules = (item: string) => console.log(fieldRules[item])
Here are my inputs:
<component
v-for="field in getFields()"
v-bind="field.props"
:mask="addMaskInputs(field.name)"
:rules="getMyRules(field.name)"
/>