saiichihashimoto / sanity-typed-schema-builder

Build Sanity schemas declaratively and get typescript types of schema values for free!
https://saiichihashimoto.github.io/sanity-typed-schema-builder
MIT License
67 stars 5 forks source link

s.array need some field types as well like name and title #212

Closed hrithikroboto closed 1 year ago

hrithikroboto commented 1 year ago
export const richText = s.array({ of: [image]});
Type '({ type: "document"; liveEdit?: boolean | undefined; orderings?: SortOrdering[] | undefined; options?: DocumentOptions | undefined; __experimental_search?: { ...; }[] | undefined; ... 13 more ...; name: "article"; } | { ...; } | { ...; })[]' is not assignable to type 'SchemaTypeDefinition[] | ComposableOption<SchemaTypeDefinition[], Omit<ConfigContext, "schema" | "currentUser" | "getClient" | "client">> | undefined'.
  Type '({ type: "document"; liveEdit?: boolean | undefined; orderings?: SortOrdering[] | undefined; options?: DocumentOptions | undefined; __experimental_search?: { ...; }[] | undefined; ... 13 more ...; name: "article"; } | { ...; } | { ...; })[]' is not assignable to type 'SchemaTypeDefinition[]'.
    Type '{ type: "document"; liveEdit?: boolean | undefined; orderings?: SortOrdering[] | undefined; options?: DocumentOptions | undefined; __experimental_search?: { ...; }[] | undefined; ... 13 more ...; name: "article"; } | { ...; } | { ...; }' is not assignable to type 'SchemaTypeDefinition'.
      Type '{ type: string; of: ItemDefinitions[]; validation: (rule: ArrayRule<{ _type: "image"; asset: SanityReference<false>; _key: string; }[]>) => RuleBuilder<ArrayRule<...>, { ...; }[]>; ... 5 more ...; icon?: ReactNode | ComponentType<...>; }' is not assignable to type 'SchemaTypeDefinition'.
        Property 'name' is missing in type '{ type: string; of: ItemDefinitions[]; validation: (rule: ArrayRule<{ _type: "image"; asset: SanityReference<false>; _key: string; }[]>) => RuleBuilder<ArrayRule<...>, { ...; }[]>; ... 5 more ...; icon?: ReactNode | ComponentType<...>; }' but required in type 'TypeAliasDefinition<string, "string" | "number" | "boolean" | "object" | "document" | "array" | "block" | "date" | "datetime" | "file" | "geopoint" | "image" | "reference" | "crossDatasetReference" | "slug" | "text" | "url" | "email">'.ts(2322)
index.d.ts(136, 3): 'name' is declared here.
saiichihashimoto commented 1 year ago

The documentation on types should explain why this isn't necessary. This replaces the type of a field, not the entire field, so there's actually no name to be had.