Closed bluehat974 closed 1 year ago
@bluehat974 would you care to share your use-case?
I'm trying to create a Monitoring component which fetch Task type from different possible api
//
type Props = {
monitoringQueryOptions: DynamicFactoryOutput<
any[],
(startDate: ISODate) => {queryKey: [string], queryFn: () => Promise<Task[]>},
{queryKey: [string], queryFn: () => Promise<Task[]>}
>
}
const Monitoring: React.FC<Props> = ({ tasksQueryOptions, taskGroupQueryOptions, retryTask }) => {
const query = useQuery(tasksQueryOptions('2000-01-01'))
...
}
const Type1Monitoring = () => {
return (
<Monitoring monitoringQueryOptions={queries.monitoring1.getTask}/>
)
}
const Type2Monitoring = () => {
return (
<Monitoring monitoringQueryOptions={queries.monitoring2.getTask}/>
)
}
@bluehat974 not sure I follow because your props don't match the component example. Can you share a reproduction on a codepen/stackblitz? But on a superficial look, I don't think what you're trying to do is gonna work with the DynamicFactoryOutput
type. With a example I can edit on codepen I can help you achieve what you're trying to do
I also like to see exposed types. My use case on this is a helper function that creates query keys like so:
export const createAllQueryKey = <TParametersGetAll>(): FactoryProperty /* is not available */ => ({
workspaceId,
fieldsToInclude = [],
params,
}:
{
workspaceId: MaybeRef<string>
fieldsToInclude?: string[]
params?: MaybeRef<TParametersGetAll>
},
) => ({
queryKey: [
workspaceId,
...fieldsToInclude,
...(params ? [params] : []),
],
enabled: !!unref(workspaceId),
})
usage:
export const queryKeys = createQueryKeys('my-key', {
all: createAllQueryKey<ParametersGetAll>()
})
I have several keys in my project that have a similar structure. So such a helper would be handy.
@lukemorales Is this a valid use case for exposing the types or would you recommend a different solution?
Is it possible to expose all the type defined in this project. I try to create a component which accept a DynamicFactoryOutput, but I can't import it at all as the type is defined privately