Skip to content
This repository has been archived by the owner on May 6, 2023. It is now read-only.

Commit

Permalink
Merge pull request #65 from saiichihashimoto/simplify-less
Browse files Browse the repository at this point in the history
fix(types): less simplifys for performance
  • Loading branch information
kodiakhq[bot] authored Jun 12, 2022
2 parents 1a581b5 + e9ad2df commit f4c16da
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 30 deletions.
17 changes: 6 additions & 11 deletions src/array/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ import type { FieldOptionKeys } from "../field";
import type { InferZod, SanityType, TypeValidation } from "../types";
import type { Faker } from "@faker-js/faker";
import type { Schema } from "@sanity/types";
import type { Simplify } from "type-fest";

type UnArray<T> = T extends Array<infer U> ? U : never;

Expand Down Expand Up @@ -67,11 +66,9 @@ interface ItemsType<
) => ItemsType<
Positions | NewPosition,
// @ts-expect-error -- Not sure how to solve this
Simplify<
Items & {
[field in NewPosition]: SanityType<ItemDefinition, Zod>;
}
>
Items & {
[field in NewPosition]: SanityType<ItemDefinition, Zod>;
}
>;
}

Expand Down Expand Up @@ -115,11 +112,9 @@ const itemsInternal = <
itemsInternal<
Positions | NewPosition,
// @ts-expect-error -- Not sure how to solve this
Simplify<
Items & {
[field in NewPosition]: SanityType<ItemDefinition, Zod>;
}
>,
Items & {
[field in NewPosition]: SanityType<ItemDefinition, Zod>;
},
NonEmpty
>([...items, item]),
});
Expand Down
38 changes: 19 additions & 19 deletions src/field/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import type {
Rule,
Schema,
} from "@sanity/types";
import type { Simplify } from "type-fest";
import type { Merge } from "type-fest";

export type FieldOptionKeys = "description" | "name" | "title";

Expand Down Expand Up @@ -93,11 +93,9 @@ export interface FieldsType<
) => FieldsType<
NewFieldNames,
// @ts-expect-error -- Not sure how to solve this
Simplify<
Fields & {
[field in Name]: FieldOptions<Name, Zod, Optional>;
}
>
Fields & {
[field in Name]: FieldOptions<Name, Zod, Optional>;
}
>;
}

Expand Down Expand Up @@ -199,11 +197,9 @@ const fieldsInternal = <
fieldsInternal<
NewFieldNames,
// @ts-expect-error -- Not sure how to solve this
Simplify<
Fields & {
[field in Name]: FieldOptions<Name, Zod, Optional>;
}
>
Fields & {
[field in Name]: FieldOptions<Name, Zod, Optional>;
}
>([...fields, options]),
};
};
Expand Down Expand Up @@ -232,15 +228,17 @@ export type Preview<
}
| {
component?: React.ComponentType<
Simplify<
Omit<Value, keyof Select> & {
Merge<
Value,
{
[field in keyof Select]: unknown;
}
>
>;
prepare: (
object: Simplify<
Omit<Value, keyof Select> & {
object: Merge<
Value,
{
[field in keyof Select]: unknown;
}
>,
Expand All @@ -250,15 +248,17 @@ export type Preview<
}
| {
component: React.ComponentType<
Simplify<
Omit<Value, keyof Select> & {
Merge<
Value,
{
[field in keyof Select]: unknown;
}
>
>;
prepare?: (
object: Simplify<
Omit<Value, keyof Select> & {
object: Merge<
Value,
{
[field in keyof Select]: unknown;
}
>,
Expand Down

0 comments on commit f4c16da

Please sign in to comment.