Skip to content

Can I refer to the other prop inside a prop? #143

Answered by johnsoncodehk
sheremet-va asked this question in Q&A
Discussion options

You must be logged in to vote

Also has a type-only way, it should be support reuse the child component. A challenge is how to define DefineComponent<...> correctly.

// child.vue
import { defineComponent, PropType } from 'vue'

interface MyObject {
  [key: string]: any
}

export default defineComponent({
  props: {
    value: Object as PropType<MyObject>,
    key: String as PropType<keyof MyObject>
  },
}) as ChildType<MyObject>;

export type ChildType<T extends MyObject> = DefineComponent<{
  value: PropType<T>,
  key: PropType<keyof T>,
}>;
// parent.vue
import { defineComponent } from 'vue'
import Child, { ChildType } from './child.vue'

export default defineComponent({
  components: {
    Child: Child as ChildType<{ 

Replies: 7 comments 12 replies

This comment has been hidden.

@sheremet-va
Comment options

@sheremet-va
Comment options

@johnsoncodehk
Comment options

Comment options

You must be logged in to vote
2 replies
@sheremet-va
Comment options

@johnsoncodehk
Comment options

Answer selected by sheremet-va
Comment options

You must be logged in to vote
2 replies
@johnsoncodehk
Comment options

@sheremet-va
Comment options

Comment options

You must be logged in to vote
4 replies
@johnsoncodehk
Comment options

@sheremet-va
Comment options

@Evertt
Comment options

@johnsoncodehk
Comment options

Comment options

You must be logged in to vote
0 replies
Comment options

You must be logged in to vote
1 reply
@sheremet-va
Comment options

Comment options

You must be logged in to vote
0 replies
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
4 participants