fix: requires client field prop in server field components (#8188)

Fixes a type error when using server components for field labels,
descriptions, and errors. The `clientField` prop will always exist, so
the types just need to be reflective of this. Here's an example:

```tsx
import type { TextFieldServerLabelComponent } from 'payload'

import { FieldLabel } from '@payloadcms/ui'
import React from 'react'

export const MyServerFieldLabelComponent: TextFieldServerLabelComponent = ({ clientField }) => {
  return <FieldLabel field={clientField} /> // `TextFieldClientWithoutType | undefined` is not assignable to type `ClientFieldWithoutType`
}
```
This commit is contained in:
Jacob Fletcher
2024-09-12 12:15:26 -04:00
committed by GitHub
parent 945d9192a1
commit c28618b19c
3 changed files with 3 additions and 3 deletions

View File

@@ -29,7 +29,7 @@ export type FieldDescriptionServerProps<
TFieldServer extends Field = Field, TFieldServer extends Field = Field,
TFieldClient extends ClientFieldWithOptionalType = ClientFieldWithOptionalType, TFieldClient extends ClientFieldWithOptionalType = ClientFieldWithOptionalType,
> = { > = {
clientField?: TFieldClient clientField: TFieldClient
readonly field: TFieldServer readonly field: TFieldServer
} & GenericDescriptionProps & } & GenericDescriptionProps &
Partial<ServerProps> Partial<ServerProps>

View File

@@ -21,7 +21,7 @@ export type FieldErrorServerProps<
TFieldServer extends Field, TFieldServer extends Field,
TFieldClient extends ClientFieldWithOptionalType = ClientFieldWithOptionalType, TFieldClient extends ClientFieldWithOptionalType = ClientFieldWithOptionalType,
> = { > = {
clientField?: TFieldClient clientField: TFieldClient
readonly field: TFieldServer readonly field: TFieldServer
} & GenericErrorProps & } & GenericErrorProps &
Partial<ServerProps> Partial<ServerProps>

View File

@@ -22,7 +22,7 @@ export type FieldLabelServerProps<
TFieldServer extends Field, TFieldServer extends Field,
TFieldClient extends ClientFieldWithOptionalType = ClientFieldWithOptionalType, TFieldClient extends ClientFieldWithOptionalType = ClientFieldWithOptionalType,
> = { > = {
clientField?: TFieldClient clientField: TFieldClient
readonly field: TFieldServer readonly field: TFieldServer
} & GenericLabelProps & } & GenericLabelProps &
Partial<ServerProps> Partial<ServerProps>