Skip to content

Commit

Permalink
Better z.instanceof
Browse files Browse the repository at this point in the history
  • Loading branch information
Colin McDonnell committed Dec 12, 2022
1 parent 42cbaae commit c3b7598
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 12 deletions.
12 changes: 6 additions & 6 deletions deno/lib/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4358,12 +4358,12 @@ export type ZodFirstPartySchemaTypes =
| ZodPipeline<any, any>;

// new approach that works for abstract classes
// but required TS 4.4+
// abstract class Class {
// constructor(..._: any[]) {}
// }
// const instanceOfType = <T extends typeof Class>(
const instanceOfType = <T extends new (...args: any[]) => any>(
// but requires TS 4.4+
abstract class Class {
constructor(..._: any[]) {}
}
const instanceOfType = <T extends typeof Class>(
// const instanceOfType = <T extends new (...args: any[]) => any>(
cls: T,
params: Parameters<ZodTypeAny["refine"]>[1] = {
message: `Input not instance of ${cls.name}`,
Expand Down
12 changes: 6 additions & 6 deletions src/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4358,12 +4358,12 @@ export type ZodFirstPartySchemaTypes =
| ZodPipeline<any, any>;

// new approach that works for abstract classes
// but required TS 4.4+
// abstract class Class {
// constructor(..._: any[]) {}
// }
// const instanceOfType = <T extends typeof Class>(
const instanceOfType = <T extends new (...args: any[]) => any>(
// but requires TS 4.4+
abstract class Class {
constructor(..._: any[]) {}
}
const instanceOfType = <T extends typeof Class>(
// const instanceOfType = <T extends new (...args: any[]) => any>(
cls: T,
params: Parameters<ZodTypeAny["refine"]>[1] = {
message: `Input not instance of ${cls.name}`,
Expand Down

0 comments on commit c3b7598

Please sign in to comment.