-
Notifications
You must be signed in to change notification settings - Fork 3.2k
docs: adds clarification around numeric field names #13596
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
base: main
Are you sure you want to change the base?
Conversation
jacobsfletch
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
tbh I'm on the fence on if we really need any documentation for this at all, I left a few comments either way, but fields don't allow numeric names in the first place.
If anything, maybe we just draw a comparison between a field config and how it relates to a response object. Then provide an example of how to access it by name (similar to what you have). Basically describe Payload, not javascript.
|
|
||
| ``` | ||
|
|
||
| That said, numeric field names are allowed but aren't recommended due to JavaScript syntax pitfalls and you should lean towards descriptive string names. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
numeric field names are allowed but aren't recommended
Is this true? We enforce strings here which throws a TS error:
| <Banner type="warning"> | ||
| Field name values must be valid JSON object keys. Although names are always | ||
| strings, using numbers as names can break expected behavior because Payload | ||
| stores all content as nested JSON. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This could be worded more straight forward. Something like:
Remember: just like all Payload field names are strings, all Payload response objects use strings as their keys.
| ```ts | ||
| import type { Field } from 'payload' | ||
|
|
||
| export const NumericFieldName: Field = { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is misleading because this field's name is not numeric, it's a string as required.
Fixes #13534