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

How to use generics in TSX #11374

Open
TaurusWood opened this issue Jul 16, 2024 · 1 comment · May be fixed by #11478
Open

How to use generics in TSX #11374

TaurusWood opened this issue Jul 16, 2024 · 1 comment · May be fixed by #11478
Labels
🍰 p2-nice-to-have Priority 2: this is not breaking anything but nice to have it addressed.

Comments

@TaurusWood
Copy link

TaurusWood commented Jul 16, 2024

Vue version

3.4.27

Link to minimal reproduction

https://play.vuejs.org/#eNp9U02PmzAQ/StTX2AlBFLbU5Yg9WOldg9ttY3UQ4i0CCYJu2BbtklTIf57x8aQ7DZNDsTz4Zk374179kHK+NAhW7BUl6qWBjSaTmY5r1splIEeFG5hgK0SLQSUGsyhz9gK748Ta8RGHylcCq4NtHoHS3s5DL5g0wj4JVRTvQlucp7zNBm7UR8yDLayKQySBZC6sgmd0+QswCJmNFXe1rv4SQtOiHubnrNStLJuUH2XpqbOOVuAi9hYQY1/3zufUR1Gk7/cY/l8wf+kj9aXsx8KNaoD5myOmULt0Izhu5/f8EjnOdiKqmso+0rwAbVoOotxTPvY8Ypgn+U5tF8duTXfrfTd0SDX01AWqM0cXH7OSItPV0Y/wX0Xv3f3cj4Qi5NQROAscYXbmrtqgiM30bnmrlHObmfZbdosuzW87JPwTr/l65pheAPLbII3ZjY1fcYdWY9+IDC8aHEBwUq0gZ/1hf++KJ9PgY1bJ3tStLeKw4s2xIP/99G0qg9uy+wvteDSqbA2ikiHIbObu8zZ3i5tzhzIZW+/8aFoOhzcbvoKyake0UsfBwePjihioOiakRAifqLqCvGv3tnEqGP8X0bda1kB7RrySsMDlkJV6ThHBAX/k2WhVEJq2go71DTjrZtpAav1hgB7uk66iAbjRuzCR5v1GIErEVuDhvs/0xcZ3r/N+vE+9R/ShOxZ0OkAZx3itpAh7UQGqcx6E1tp6JrMfGtP82Xu3Ur4sn7udUB9gwgCWzzY+GdwSSRLKxv+Ai3howE=

Steps to reproduce

In the official use case, when defining components using defineComponent, an example of using generics is as follows:

const Comp = defineComponent(
  <T extends string | number>(props: { msg: T; list: T[] }) => {
    // use Composition API here like in <script setup>
    const count = ref(0)

    return () => {
      // render function or JSX
      return <div>{count.value}</div>
    }
  },
  // manual runtime props declaration is currently still needed.
  {
    props: ['msg', 'list']
  }
)

I know that generic can be used to define in composite APIs, but child components and parent components are defined by defineComponent, so I want to know how to pass generic from the parent component in tsx###

What is expected?

like react, we can pass generics like this:

  return () => {
      
    return (
      <div>
        <Comp<{ name: string }> msg="hello" list={list.value} />
      </div>)
    }

What is actually happening?

I couldn't find any way to pass generics into child components,like this
WX20240717-095810

System Info

No response

Any additional comments?

No response

@yyx990803 yyx990803 added the 🍰 p2-nice-to-have Priority 2: this is not breaking anything but nice to have it addressed. label Jul 17, 2024
@Procrustes5
Copy link
Contributor

Procrustes5 commented Aug 3, 2024

#11478
I made PR, is this the same thing you wanted?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
🍰 p2-nice-to-have Priority 2: this is not breaking anything but nice to have it addressed.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants