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

Add Any Field Type #331

Closed
kouliavtsev opened this issue Nov 15, 2022 · 4 comments
Closed

Add Any Field Type #331

kouliavtsev opened this issue Nov 15, 2022 · 4 comments

Comments

@kouliavtsev
Copy link

In contentlayer 2.7, the string definition would work like any, after the upgrade to 2.8 if the data is not a string an error is thrown. This is correct behavior, yet if you are not able to change the data source you are stuck using contentlayer 2.7.

A good example would be a yaml config file with fields null, true, some string, etc.

// ...
defaultValue: {
  type: "any",
},
# item 1
defaultValue: null
# item 2
defaultValue: true
# item 3
defaultValue: some string

Even though, using any looks like introducing an anti-pattern. I think it has a viable use case.

Similarly, the Add Union Field Type could solve this problem. Yet, it seems a bit harder to implement.

@stale
Copy link

stale bot commented Jan 14, 2023

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.

@stale stale bot added the meta: stale label Jan 14, 2023
@kouliavtsev
Copy link
Author

Would love to see this implemented.

@stale stale bot removed the meta: stale label Jan 14, 2023
@schickling schickling added this to the 0.2.10 milestone Jan 14, 2023
@schickling
Copy link
Collaborator

schickling commented Jan 17, 2023

Would the already existing json type work for you? @kouliavtsev

@schickling schickling removed this from the 0.2.10 milestone Jan 17, 2023
@kouliavtsev
Copy link
Author

@schickling

This helped with solving the issue. Thanks a ton!

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

No branches or pull requests

2 participants