You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I'm writing a small library for Vue 3 which contains a function
functionfn(component,props){}
which takes a component definition (component options) as first argument and the component's props as second argument. These props will be passed to an actual instance of the component later.
Given a component definition, I want to provide the actual type of the props to the user. Idea:
My call to fn would then type the second parameter as { prop1: string }
importSomeComponentfrom'...';// Type checking okfn(SomeComponent,{prop1: 'test'})// This would failfn(SomeComponent,{prop2 : 1})
I had something similar working for a beta of Vue 3 here, but this no longer works (as of rc 1). I wanted to rebuild this with rc 1, but it seems I can't, because one of the returned types of defineComponent (ComponentPublicInstanceConstructor) is not exported and thus I can't use it in my conditional type.
So:
Is this currently possible and I just missed how?
Is this approach even idiomatic or is there an alternative "best practice" approach for this?
Thanks.
What does the proposed API look like?
Not sure, maybe exporting ComponentPublicInstanceConstructor is sufficient?
The text was updated successfully, but these errors were encountered:
If the type you got is a return type from defineComponent, it is a constructor so you should be able to get its props type as InstanceType<TComponent>['$props']. This is also what TSX uses to infer props.
What problem does this feature solve?
I'm writing a small library for Vue 3 which contains a function
which takes a component definition (component options) as first argument and the component's props as second argument. These props will be passed to an actual instance of the component later.
Given a component definition, I want to provide the actual type of the props to the user. Idea:
So if I had a component like this:
My call to
fn
would then type the second parameter as{ prop1: string }
I had something similar working for a beta of Vue 3 here, but this no longer works (as of rc 1). I wanted to rebuild this with rc 1, but it seems I can't, because one of the returned types of
defineComponent
(ComponentPublicInstanceConstructor
) is not exported and thus I can't use it in my conditional type.So:
Thanks.
What does the proposed API look like?
Not sure, maybe exporting
ComponentPublicInstanceConstructor
is sufficient?The text was updated successfully, but these errors were encountered: