Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Generic form on T access with keyof T #2082

Open
ThibaudDauce opened this issue Nov 8, 2024 · 0 comments
Open

Generic form on T access with keyof T #2082

ThibaudDauce opened this issue Nov 8, 2024 · 0 comments

Comments

@ThibaudDauce
Copy link

Version:

  • @inertiajs/vue3 version: 1.2.0

Describe the problem:

When I try to access my form on a generic model T with a key: keyof T, Typescript raised an issue.

Steps to reproduce:

<template>
  <div>
    <!-- Working -->
    <div>{{ form[key] }}</div>

    <!-- Working -->
    <div>{{ model[genericKey] }}</div>

    <!-- Type 'keyof T' cannot be used to index type 'DistributeRef<InertiaForm<T>> -->
    <div>{{ genericForm[genericKey] }}</div>
  </div>
</template>

<script setup lang="ts" generic="T extends object">
import { InertiaForm, useForm } from '@inertiajs/vue3';

const props = defineProps<{
  model: T;
  genericKey: keyof T;
}>();

// Test with non generic default values
const defaultValues = { name: 'Thibaud' };
const form = useForm(defaultValues);
const key = 'name' as keyof typeof defaultValues;

const genericForm: InertiaForm<T> = useForm(props.model);
</script>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant