As of now, Vuetify does not directly export the type. However, you can obtain it by extracting it from component declarations, similar to the approach outlined in this referenced answer:
import type { VTextField } from 'vuetify/components'
type UnwrapReadonlyArray<A> = A extends Readonly<Array<infer I>> ? I : A;
type ValidationRule = UnwrapReadonlyArray<VTextField['rules']>
The specific component used is not crucial, as long as it utilizes the ValidationRule
type. In this case, VTextField incorporates a :rules
prop, which is why it is being leveraged here.
Accessing the rules
index results in the type readonly ValidationRule[]
.
Ultimately, the UnwrapReadonlyArray
type helps in extracting the array item type and eliminating the readonly modifier.
Prior to Vuetify 3.4, constructor functions were exported instead of types, necessitating the construction of the type manually:
type VTextFieldType = InstanceType<typeof VTextField>
type ValidationRule = UnwrapReadonlyArray<VTextFieldType['rules']>