Skip to content

Commit

Permalink
fix: remove instanceof
Browse files Browse the repository at this point in the history
  • Loading branch information
ItMaga committed Apr 12, 2023
1 parent f3f937c commit fec4a42
Showing 1 changed file with 8 additions and 6 deletions.
14 changes: 8 additions & 6 deletions lib/generators/IntersectionGenerator.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,15 @@ import type BaseGenerator from './BaseGenerator';

export default class IntersectionGenerator<T extends z.ZodIntersection<z.ZodTypeAny, z.ZodTypeAny>> implements BaseGenerator<T> {
public generate(schema: T) {
if (schema._def.left instanceof z.ZodUnion && schema._def.right instanceof z.ZodUnion) {
const sharedOptions = schema._def.left._def.options.filter((leftOption: z.ZodTypeAny) => {
return schema._def.right._def.options.some((rightOption: z.ZodTypeAny) => rightOption._def.typeName === leftOption._def.typeName);
});
if ('typeName' in schema._def.left && 'typeName' in schema._def.right) {
if (schema._def.left.typeName === 'ZodUnion' && schema._def.right.typeName === 'ZodUnion') {
const sharedOptions = schema._def.left._def.options.filter((leftOption: z.ZodTypeAny) => {
return schema._def.right._def.options.some((rightOption: z.ZodTypeAny) => rightOption._def.typeName === leftOption._def.typeName);
});

const mockGenerator = new MockGenerator(z.union(sharedOptions));
return mockGenerator.generate();
const mockGenerator = new MockGenerator(z.union(sharedOptions));
return mockGenerator.generate();
}
}

const leftGenerated = new MockGenerator(schema._def.left).generate();
Expand Down

0 comments on commit fec4a42

Please sign in to comment.