以下是代码:
exp或t const quickPrompt = async <T>({
name,
prompt,
zodSchema,
onUpdate,
}: {
name: string;
onUpdate: () => Promise<{ cancelled: boolean }>;
prompt: string;
zodSchema?: z.ZodType<T>;
}): Promise<T extends undefined ? string : T> => {
下面是它的调用方式:
const content = await quickPrompt({
name: 'writeArticleSection',
onUpdate,
prompt,
});
或
const content = await quickPrompt({
name: 'writeArticleSection',
onUpdate,
prompt,
zodSchema: z.array(z.string())
});
在第一种情况下,我预计content
将具有类型string
(因为T extends
未定义) and in the second I expect it to be
字符串[](because
Tdoes not extend
未定义`)
I've tried using T extends never
and such, but I cannot get it to w或k as expected.