-
-
Notifications
You must be signed in to change notification settings - Fork 1.2k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix(client+server): non-records inferred as records
- Loading branch information
1 parent
275cf3c
commit cbac018
Showing
2 changed files
with
38 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
35 changes: 35 additions & 0 deletions
35
packages/tests/server/regression/issue-5075-complex-zod-serialized-inference.test.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
import { inferRouterOutputs, initTRPC } from '@trpc/server'; | ||
import * as z from 'zod'; | ||
|
||
describe('Non-records should not erroneously be inferred as Records in serialized types', () => { | ||
const zChange = z.object({ | ||
status: z | ||
.tuple([ | ||
z.literal('tmp').or(z.literal('active')), | ||
z.literal('active').or(z.literal('disabled')), | ||
]) | ||
.optional(), | ||
validFrom: z.tuple([z.string().nullable(), z.string()]).optional(), | ||
validTo: z.tuple([z.string().nullable(), z.string().nullable()]).optional(), | ||
canceled: z.tuple([z.boolean(), z.boolean()]).optional(), | ||
startsAt: z | ||
.tuple([z.string().nullable(), z.string().nullable()]) | ||
.optional(), | ||
endsAt: z.tuple([z.string().nullable(), z.string().nullable()]).optional(), | ||
}); | ||
type Change = z.infer<typeof zChange>; | ||
|
||
test('should be inferred as object', () => { | ||
const t = initTRPC.create(); | ||
|
||
const router = t.router({ | ||
createProject: t.procedure.output(zChange).query(() => { | ||
return zChange.parse(null as any); | ||
}), | ||
}); | ||
|
||
type SerializedOutput = inferRouterOutputs<typeof router>['createProject']; | ||
|
||
expectTypeOf<SerializedOutput>().toEqualTypeOf<Change>(); | ||
}); | ||
}); |