Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat!: re-order DefaultCellComponentProps generics #9207

Merged
merged 1 commit into from
Nov 14, 2024

Conversation

JarrodMFlesch
Copy link
Contributor

@JarrodMFlesch JarrodMFlesch commented Nov 14, 2024

What?

Changes the order of the DefaultCellComponentProps generic type, allowing us to infer the type of cellData when a ClientField type is passed as the first generic argument. You can override the cellData type by passing the second generic.

Previously:

type DefaultCellComponentProps<TCellData = any, TField extends ClientField = ClientField>

New:

type DefaultCellComponentProps<TField extends ClientField = ClientField, TCellData = undefined>

Why?

Changing the ClientField type to be the first argument allows us to infer the cellData value type based on the type of field.

I could have kept the same signature but the usage would look like:

// Not very DX friendly
const MyCellComponent<DefaultCellComponentProps<,ClientField>> = () => null

How?

The changes made here allow this. You can override the type by passing in the second argument to the generic.

@JarrodMFlesch JarrodMFlesch changed the title feat!: adjusts DefaultServerCellComponentProps generics feat!: adjusts DefaultCellComponentProps generics Nov 14, 2024
@JarrodMFlesch JarrodMFlesch changed the title feat!: adjusts DefaultCellComponentProps generics feat!: re-order DefaultCellComponentProps generics Nov 14, 2024
@JarrodMFlesch JarrodMFlesch merged commit 77c99c2 into beta Nov 14, 2024
70 checks passed
@JarrodMFlesch JarrodMFlesch deleted the chore/beta/simplify-DefaultCellComponentProps branch November 14, 2024 17:31
jacobsfletch pushed a commit that referenced this pull request Nov 14, 2024
### What?
Changes the order of the `DefaultCellComponentProps` generic type,
allowing us to infer the type of cellData when a ClientField type is
passed as the first generic argument. You can override the cellData type
by passing the second generic.

Previously:
```ts
type DefaultCellComponentProps<TCellData = any, TField extends ClientField = ClientField>
```

New:
```ts
type DefaultCellComponentProps<TField extends ClientField = ClientField, TCellData = undefined>
```

### Why?
Changing the ClientField type to be the first argument allows us to
infer the cellData value type based on the type of field.

I could have kept the same signature but the usage would look like:
```ts
// Not very DX friendly
const MyCellComponent<DefaultCellComponentProps<,ClientField>> = () => null
```

### How?
The changes made
[here](https://github.com/payloadcms/payload/compare/chore/beta/simplify-DefaultCellComponentProps?expand=1#diff-24f3c92e546c2be3fed0bab305236bba83001309a7239c20a3e3dbd6f5f71dc6R29-R73)
allow this. You can override the type by passing in the second argument
to the generic.
Copy link

🚀 This is included in version v3.0.0-beta.131

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant