@ryanchenkie
Developer Advocate at Prisma
@ryanchenkie
@prisma
function add(num1, num2) {
return num1 + num2;
}
add(1, "foo");
@ryanchenkie
@prisma
function add(num1: number, num2: number) {
return num1 + num2;
}
add(1, "foo"); // compilation error
@ryanchenkie
@prisma
@ryanchenkie
@prisma
type IsValid<
T extends Prisma.PrismaClient,
U extends keyof T
> = RequiredMethods extends keyof T[U]
? T[U][RequiredMethods] extends (args?: any) => any
? 1
: 0
: 0
type RequiredMethods = 'create' | 'findUnique' | 'delete' | 'update'
type Filter<T extends Prisma.PrismaClient> = {
[K in keyof T]-?: {
1: K
0: never
}[IsValid<T, K>]
}[keyof T]
@ryanchenkie
@prisma
Generics
Index Type Query and Lookup Types
Template Literal Types
@ryanchenkie
@prisma
@ryanchenkie