Currently working with Vue and Typescript, I'm exploring different ways to describe types for an array of functions. In my current code, I have the following setup. Is there a way I could define an interface called formRules
instead of repeatedly declaring the types
Array<(v: string) => boolean | string>
or just <(v: string) => boolean | string>
?
<script lang="ts">
import { Vue, Component } from 'vue-property-decorator';
@Component({
name: 'signUpForm',
})
export default class SignUpForm extends Vue {
private valid = true
private firstName = ''
private lastName = ''
private nameRules: Array<(v: string) => boolean | string> = [
(v) => !!v || 'Name is required',
]
private email = ''
private emailRules: Array<(v: string) => boolean | string> = [
(v) => !!v || 'E-mail is required',
(v) => /.+@.+\..+/.test(v) || 'E-mail must be valid',
]
}
</script>