-
-
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.
- Loading branch information
Showing
2 changed files
with
226 additions
and
23 deletions.
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
168 changes: 168 additions & 0 deletions
168
packages/tests/server/regression/issue-5197-output-with-index-signature-and-record.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,168 @@ | ||
import { inferRouterOutputs, initTRPC } from '@trpc/server'; | ||
|
||
const t = initTRPC.create(); | ||
|
||
const appRouter = t.router({ | ||
outputWithIndexSignature: t.procedure.query(() => { | ||
return {} as { | ||
a: number; | ||
b: number; | ||
[c: string]: number; | ||
}; | ||
}), | ||
|
||
outputWithRecord: t.procedure.query(() => { | ||
return {} as { | ||
a: number; | ||
b: number; | ||
} & Record<string, number>; | ||
}), | ||
|
||
outputWithRecordAndIndexSignature: t.procedure.query(() => { | ||
return {} as { | ||
a: number; | ||
b: number; | ||
[c: string]: number; | ||
} & Record<string, number>; | ||
}), | ||
|
||
outputWithUndefinedAndUndefinedIndexSignature: t.procedure.query(() => { | ||
return {} as { | ||
a: number; | ||
b: number | undefined; | ||
[c: string]: number | undefined; | ||
}; | ||
}), | ||
|
||
outputWithUndefinedAndUndefinedRecord: t.procedure.query(() => { | ||
return {} as { | ||
a: number; | ||
b: number | undefined; | ||
} & Record<string, number | undefined>; | ||
}), | ||
|
||
outputWithUndefinedAndUndefinedRecordAndUndefinedIndexSignature: | ||
t.procedure.query(() => { | ||
return {} as { | ||
a: number; | ||
b: number | undefined; | ||
[c: string]: number | undefined; | ||
} & Record<string, number | undefined>; | ||
}), | ||
|
||
outputWithUndefinedIndexSignature: t.procedure.query(() => { | ||
return {} as { | ||
a: number; | ||
b: number; | ||
[c: string]: number | undefined; | ||
}; | ||
}), | ||
|
||
outputWithUndefinedRecord: t.procedure.query(() => { | ||
return {} as { | ||
a: number; | ||
b: number; | ||
} & Record<string, number | undefined>; | ||
}), | ||
|
||
outputWithUndefinedRecordAndUndefinedIndexSignature: t.procedure.query(() => { | ||
return {} as { | ||
a: number; | ||
b: number; | ||
[c: string]: number | undefined; | ||
} & Record<string, number | undefined>; | ||
}), | ||
}); | ||
|
||
type AppRouter = typeof appRouter; | ||
|
||
describe('inferRouterOutputs', () => { | ||
type AppRouterOutputs = inferRouterOutputs<AppRouter>; | ||
|
||
test('outputWithIndexSignature', () => { | ||
type Output = AppRouterOutputs['outputWithIndexSignature']; | ||
expectTypeOf<Output>().toEqualTypeOf<{ | ||
[x: string]: number; | ||
[x: number]: number; | ||
a: number; | ||
b: number; | ||
}>(); | ||
}); | ||
|
||
test('outputWithRecord', () => { | ||
type Output = AppRouterOutputs['outputWithRecord']; | ||
expectTypeOf<Output>().toEqualTypeOf<{ | ||
[x: string]: number; | ||
a: number; | ||
b: number; | ||
}>(); | ||
}); | ||
|
||
test('outputWithRecordAndIndexSignature', () => { | ||
type Output = AppRouterOutputs['outputWithRecordAndIndexSignature']; | ||
expectTypeOf<Output>().toEqualTypeOf<{ | ||
[x: string]: number; | ||
[x: number]: number; | ||
a: number; | ||
b: number; | ||
}>(); | ||
}); | ||
|
||
test('outputWithUndefinedAndUndefinedIndexSignature', () => { | ||
type Output = | ||
AppRouterOutputs['outputWithUndefinedAndUndefinedIndexSignature']; | ||
expectTypeOf<Output>().toEqualTypeOf<{ | ||
[x: string]: number; | ||
[x: number]: number; | ||
a: number; | ||
}>(); | ||
}); | ||
|
||
test('outputWithUndefinedAndRecord', () => { | ||
type Output = AppRouterOutputs['outputWithUndefinedAndUndefinedRecord']; | ||
expectTypeOf<Output>().toEqualTypeOf<{ | ||
[x: string]: number; | ||
a: number; | ||
}>(); | ||
}); | ||
|
||
test('outputWithUndefinedAndRecordAndIndexSignature', () => { | ||
type Output = | ||
AppRouterOutputs['outputWithUndefinedAndUndefinedRecordAndUndefinedIndexSignature']; | ||
expectTypeOf<Output>().toEqualTypeOf<{ | ||
[x: string]: number; | ||
[x: number]: number; | ||
a: number; | ||
}>(); | ||
}); | ||
|
||
test('outputWithUndefinedIndexSignature', () => { | ||
type Output = AppRouterOutputs['outputWithUndefinedIndexSignature']; | ||
expectTypeOf<Output>().toEqualTypeOf<{ | ||
[x: string]: number; | ||
[x: number]: number; | ||
a: number; | ||
b: number; | ||
}>(); | ||
}); | ||
|
||
test('outputWithUndefinedRecord', () => { | ||
type Output = AppRouterOutputs['outputWithUndefinedRecord']; | ||
expectTypeOf<Output>().toEqualTypeOf<{ | ||
[x: string]: number; | ||
a: number; | ||
b: number; | ||
}>(); | ||
}); | ||
|
||
test('outputWithUndefinedRecordAndUndefinedIndexSignature', () => { | ||
type Output = | ||
AppRouterOutputs['outputWithUndefinedRecordAndUndefinedIndexSignature']; | ||
expectTypeOf<Output>().toEqualTypeOf<{ | ||
[x: string]: number; | ||
[x: number]: number; | ||
a: number; | ||
b: number; | ||
}>(); | ||
}); | ||
}); |
b005dc6
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Successfully deployed to the following URLs:
next-prisma-starter – ./examples/next-prisma-starter
next-prisma-starter-trpc.vercel.app
next-prisma-starter-git-main-trpc.vercel.app
nextjs.trpc.io
b005dc6
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Successfully deployed to the following URLs:
og-image – ./www/og-image
og-image-trpc.vercel.app
og-image-three-neon.vercel.app
og-image.trpc.io
og-image-git-main-trpc.vercel.app
b005dc6
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Successfully deployed to the following URLs:
www – ./www
www-trpc.vercel.app
beta.trpc.io
www-git-main-trpc.vercel.app
www.trpc.io
trpc.io
alpha.trpc.io