precognition icon indicating copy to clipboard operation
precognition copied to clipboard

Fix/add dot notation types to data object

Open anned20 opened this issue 1 year ago • 2 comments

Because lodashes get and set are used and the errors in the response for nested fields are based on dot notation, the selectors for these fields can also be in dot notation. This pull request adds support for that notation to the Data interface.

anned20 avatar Jul 08 '24 14:07 anned20

@anned20, I'm not sure what this PR does. Can you please elaborate on what you are trying to achieve with it?

timacdonald avatar Jul 29 '24 22:07 timacdonald

@timacdonald, when using nested fields, you need to use the dot-notation: parent.child. This PR adds TypeScript support for those keys so that they are strictly typed.

anned20 avatar Jul 30 '24 08:07 anned20

@anned20, appreciate the work you have done here. I'm not sure we want to support this right now until I see some more demand for the feature.

As a side note, if we return to this, I anticipate there would be issues with arrays where the index of the array is determined at runtime.

timacdonald avatar Sep 03 '24 00:09 timacdonald

Please reconsider merging this pr or building a feature similar to this one. any nested fields do not have any type support.

Something like this

interface Product {
    id: number;
    name: string;
    short_code: string;
}

const productForm = useForm<{
    name: string;
    product: Product | null;
}>('post', 'admin/products', {
    name: '',
    product: null,
});

// in template
<input v-model="productForm.product.short_code" />

// in script
productForm.validate('product.short_code') // does not work
// Argument of type '"product.short_code"' is not assignable to parameter of type '"product" | "name" | NamedInputEvent | ValidationConfig | undefined'

SevenLab-nl avatar Jan 09 '25 16:01 SevenLab-nl