Skip to content

Using Nested Objects List in Computed Fields not allowed #358

Description

@khinshankhan

Looking at https://www.contentlayer.dev/docs/reference/source-files/field-types#nested-objects-list I'd like to be able to make computed fields lists strongly typed like that.

Using the example but changing fields to computedFields:

const Tag = defineNestedType(() => ({
  name: 'Tag',
  fields: {
    title: { type: 'string', required: true },
  },
}))

defineDocumentType(() => ({
  // ...
  computedFields: {
    // ...
    tags: {
      type: 'list',
      of: Tag,
    },
  },
}))

I get the following error:

 fields.tsx    79   7 error    2322   Type '{ type: "list"; of: NestedType<string>; resolve: (doc: GetDocumentTypeGen<T>) => { title: string; }[]; }' is not assignable to type 'ComputedField<T>'.
   Object literal may only specify known properties, and 'of' does not exist in type 'ComputedField<T>'. (lsp)

How should I go about strongly typing computed json/ lists?

Metadata

Metadata

Assignees

No one assigned

    Labels

    duplicateThis issue or pull request already exists

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions