Skip to content

Commit

Permalink
fix(client): $transaction type fallback (#5794)
Browse files Browse the repository at this point in the history
  • Loading branch information
williamluke4 committed Feb 23, 2021
1 parent 7032749 commit 9dd0d15
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 3 deletions.
Expand Up @@ -300,8 +300,9 @@ exports[`exhaustive-schema: generatedTypeScript 1`] = `
import * as runtime from '@prisma/client/runtime';
declare const prisma: unique symbol
export type PrismaPromise<A> = Promise<A> & {[prisma]: true}
type UnwrapPromise<P extends any> = P extends Promise<infer R> ? R : P
type UnwrapTuple<Tuple extends readonly unknown[]> = {
[K in keyof Tuple]: K extends \`\${number}\` ? Tuple[K] extends PrismaPromise<infer X> ? X : never : never
[K in keyof Tuple]: K extends \`\${number}\` ? Tuple[K] extends PrismaPromise<infer X> ? X : UnwrapPromise<Tuple[K]> : UnwrapPromise<Tuple[K]>
};


Expand Down
8 changes: 7 additions & 1 deletion src/packages/client/src/__tests__/types/$transaction/test.ts
@@ -1,4 +1,4 @@
import { PrismaClient } from '@prisma/client'
import { PrismaClient, User } from '@prisma/client'

// tslint:disable

Expand All @@ -21,6 +21,12 @@ async function main() {
prisma.$queryRaw`SELECT 1`,
prisma.$executeRaw(''),
])
// Test Type Fallback
const txs = [
prisma.user.findMany(),
prisma.user.findFirst()
]
const res: (User | User[] | null)[] = await prisma.$transaction(txs)
}

main().catch((e) => {
Expand Down
3 changes: 2 additions & 1 deletion src/packages/client/src/generation/TSClient/common.ts
Expand Up @@ -102,8 +102,9 @@ export const commonCodeTS = ({
tsWithoutNamespace: () => `import * as runtime from '${runtimePath}';
declare const prisma: unique symbol
export type PrismaPromise<A> = Promise<A> & {[prisma]: true}
type UnwrapPromise<P extends any> = P extends Promise<infer R> ? R : P
type UnwrapTuple<Tuple extends readonly unknown[]> = {
[K in keyof Tuple]: K extends \`\$\{number\}\` ? Tuple[K] extends PrismaPromise<infer X> ? X : never : never
[K in keyof Tuple]: K extends \`\$\{number\}\` ? Tuple[K] extends PrismaPromise<infer X> ? X : UnwrapPromise<Tuple[K]> : UnwrapPromise<Tuple[K]>
};
`,
ts: (hideFetcher?: boolean) => `export import DMMF = runtime.DMMF
Expand Down

0 comments on commit 9dd0d15

Please sign in to comment.