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

DataViews: abandon the ItemRecord type #64367

Merged
merged 1 commit into from
Aug 8, 2024
Merged

Conversation

jsnajdr
Copy link
Member

@jsnajdr jsnajdr commented Aug 8, 2024

Implements a suggestion from #64199 (comment):

  • remove the ItemRecord type
  • make Field.getValue always optional
  • in the default getValue implementation, cast item to any to prevent type errors

This greatly simplified the types, at the cost of slightly decreased type safety. Which is very theoretical anyway and IMO has little impact in practice.

Accessing item[ field.id ] will crash if item is undefined or null. It's true that the types don't prevent that, and that ideally they should. But almost all JS values support the property access operator, including primitives like numbers.

@jsnajdr jsnajdr added [Type] Code Quality Issues or PRs that relate to code quality [Package] DataViews /packages/dataviews labels Aug 8, 2024
@jsnajdr jsnajdr requested review from youknowriad and sirreal August 8, 2024 10:31
@jsnajdr jsnajdr self-assigned this Aug 8, 2024
Copy link

github-actions bot commented Aug 8, 2024

The following accounts have interacted with this PR and/or linked issues. I will continue to update these lists as activity occurs. You can also manually ask me to refresh this list by adding the props-bot label.

If you're merging code through a pull request on GitHub, copy and paste the following into the bottom of the merge commit message.

Co-authored-by: jsnajdr <jsnajdr@git.wordpress.org>
Co-authored-by: youknowriad <youknowriad@git.wordpress.org>

To understand the WordPress project's expectations around crediting contributors, please review the Contributor Attribution page in the Core Handbook.

@youknowriad
Copy link
Contributor

I'm happy to go with this. I agree it's a small detail that doesn't have a huge impact.

@jsnajdr jsnajdr merged commit 098c1a2 into trunk Aug 8, 2024
69 checks passed
@jsnajdr jsnajdr deleted the update/dataviews-getvalue-type branch August 8, 2024 11:15
@github-actions github-actions bot added this to the Gutenberg 19.1 milestone Aug 8, 2024
Copy link
Member

@sirreal sirreal left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This seems like a good direction 👍

getdave pushed a commit that referenced this pull request Aug 14, 2024
Co-authored-by: jsnajdr <jsnajdr@git.wordpress.org>
Co-authored-by: youknowriad <youknowriad@git.wordpress.org>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
[Package] DataViews /packages/dataviews [Type] Code Quality Issues or PRs that relate to code quality
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants