Skip to content

Lack of strongly-typed examples #14135

@denolfe

Description

@denolfe

Documentation Issue

There are a lack of examples in the docs using strongly-typed Access Control and Hooks.

Additional Details

For example:

After Change Hook

Current Docs:

import type { CollectionAfterChangeHook } from 'payload'

const afterChangeHook: CollectionAfterChangeHook = async ({ doc }) => {
  return doc
}

Strongly-typed using generated types:

import type { CollectionAfterChangeHook } from 'payload'

import type { Config, Page } from '../../../payload-types'

export const revalidatePage: CollectionAfterChangeHook<Page> = ({
  doc,
  previousDoc,
  req: { payload, locale },
}) => {
  // doc and previous doc are now fully typed

  return doc
}

Access Control

Current Docs

const access = ({ req }) => {
  // Grant access if the locale is 'en'
  if (req.locale === 'en') {
    return true
  }

  // Deny access for all other locales
  return false
}

Updated docs should use Access<T> generic

Metadata

Metadata

Assignees

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions