mirror of
https://github.com/withastro/astro.git
synced 2025-02-17 22:44:24 -05:00
Actions: fix missing orThrow type when input is omitted (#11658)
* fix: orThrow missing when input is omitted * chore: changeset
This commit is contained in:
parent
a851021498
commit
13b912a870
3 changed files with 21 additions and 5 deletions
5
.changeset/gold-seas-crash.md
Normal file
5
.changeset/gold-seas-crash.md
Normal file
|
@ -0,0 +1,5 @@
|
||||||
|
---
|
||||||
|
'astro': patch
|
||||||
|
---
|
||||||
|
|
||||||
|
Fixes `orThrow()` type when calling an Action without an `input` validator.
|
|
@ -39,7 +39,7 @@ export type ActionClient<
|
||||||
input: TAccept extends 'form' ? FormData : z.input<TInputSchema>,
|
input: TAccept extends 'form' ? FormData : z.input<TInputSchema>,
|
||||||
) => Promise<Awaited<TOutput>>;
|
) => Promise<Awaited<TOutput>>;
|
||||||
}
|
}
|
||||||
: (input?: any) => Promise<SafeResult<never, Awaited<TOutput>>> & {
|
: ((input?: any) => Promise<SafeResult<never, Awaited<TOutput>>>) & {
|
||||||
orThrow: (input?: any) => Promise<Awaited<TOutput>>;
|
orThrow: (input?: any) => Promise<Awaited<TOutput>>;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
|
@ -9,8 +9,7 @@ import { z } from '../../zod.mjs';
|
||||||
|
|
||||||
describe('ActionReturnType', () => {
|
describe('ActionReturnType', () => {
|
||||||
it('Infers action return type', async () => {
|
it('Infers action return type', async () => {
|
||||||
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
const _action = defineAction({
|
||||||
const action = defineAction({
|
|
||||||
input: z.object({
|
input: z.object({
|
||||||
name: z.string(),
|
name: z.string(),
|
||||||
}),
|
}),
|
||||||
|
@ -18,9 +17,21 @@ describe('ActionReturnType', () => {
|
||||||
return { name };
|
return { name };
|
||||||
},
|
},
|
||||||
});
|
});
|
||||||
expectTypeOf<ActionReturnType<typeof action>>().toEqualTypeOf<
|
expectTypeOf<ActionReturnType<typeof _action>>().toEqualTypeOf<
|
||||||
SafeResult<any, { name: string }>
|
SafeResult<any, { name: string }>
|
||||||
>();
|
>();
|
||||||
expectTypeOf<ActionReturnType<typeof action.orThrow>>().toEqualTypeOf<{ name: string }>();
|
expectTypeOf<ActionReturnType<typeof _action.orThrow>>().toEqualTypeOf<{ name: string }>();
|
||||||
|
});
|
||||||
|
|
||||||
|
it('Infers action return type when input is omitted', async () => {
|
||||||
|
const _action = defineAction({
|
||||||
|
handler: async () => {
|
||||||
|
return { name: 'Ben' };
|
||||||
|
},
|
||||||
|
});
|
||||||
|
expectTypeOf<ActionReturnType<typeof _action>>().toEqualTypeOf<
|
||||||
|
SafeResult<any, { name: string }>
|
||||||
|
>();
|
||||||
|
expectTypeOf<ActionReturnType<typeof _action.orThrow>>().toEqualTypeOf<{ name: string }>();
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
Loading…
Add table
Reference in a new issue