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: update types #2156

Merged
merged 11 commits into from Sep 18, 2023
Merged

feat: update types #2156

merged 11 commits into from Sep 18, 2023

Conversation

Barbapapazes
Copy link
Contributor

πŸ”— Linked issue

❓ Type of change

  • πŸ“– Documentation (updates to the documentation or readme)
  • 🐞 Bug fix (a non-breaking change that fixes an issue)
  • πŸ‘Œ Enhancement (improving an existing functionality like performance)
  • ✨ New feature (a non-breaking change that adds functionality)
  • ⚠️ Breaking change (fix or feature that would cause existing functionality to change)

πŸ“š Description

I update types in useContent in order to have a better types completion and to allow user to pass it's own type.

πŸ“ Checklist

  • I have linked an issue or discussion.
  • I have updated the documentation accordingly.

@netlify
Copy link

netlify bot commented Jul 8, 2023

βœ… Deploy Preview for nuxt-content ready!

Built without sensitive environment variables

Name Link
πŸ”¨ Latest commit a9a9f57
πŸ” Latest deploy log https://app.netlify.com/sites/nuxt-content/deploys/65048a422998a80008e2856a
😎 Deploy Preview https://deploy-preview-2156--nuxt-content.netlify.app
πŸ“± Preview on mobile
Toggle QR Code...

QR Code

Use your smartphone camera to open QR code link.

To edit notification comments on pull requests, go to your Netlify site configuration.

@Barbapapazes Barbapapazes marked this pull request as ready for review July 8, 2023 18:58
@@ -71,12 +71,12 @@ export const useContent = () => {
/**
* Next page from `surround`.
*/
const next = computed(() => surround.value?.[1])
const next = computed(() => surround.value[1])
Copy link
Member

Choose a reason for hiding this comment

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

It is safe to keep this as optional because surround.value could be undefined


/**
* Previous page from `surround`.
*/
const prev = computed(() => surround.value?.[0])
const prev = computed(() => surround.value[0])
Copy link
Member

Choose a reason for hiding this comment

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

It is safe to keep this as optional because surround.value could be undefined

Copy link
Contributor Author

Choose a reason for hiding this comment

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

In which case? As I can experiment, there is always a value and the object could be [null, null]

Copy link
Member

Choose a reason for hiding this comment

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

surrounds is set inside documentDriven.ts only if HTTP call succeeds, if HTTP call fails surround will be null

Also, it will be null if users disable surrounds in document driven.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Ho yes, that's a good point.

/**
* Layout
*/
layout: string
Copy link
Member

Choose a reason for hiding this comment

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

layout should be an optional field because it may or may not present in front-matter.
I'm also thinking of moving it to ParsedContentMeta

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yes, good catch for the undefined.

Should we moved it to ParsedMeta, I don't know. I myself asked the question and I understand that ParsedMeta are calculated and because layout is not, I added here. But i'm completely open to move it.

Copy link
Member

Choose a reason for hiding this comment

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

I think ParsedMeta is better place for it

@manniL
Copy link
Member

manniL commented Sep 14, 2023

Will this allow typing the page that comes back by any chance?

@Barbapapazes
Copy link
Contributor Author

Will this allow typing the page that comes back by any chance?

Could you tell me which pages?

@manniL
Copy link
Member

manniL commented Sep 15, 2023

@Barbapapazes I was thinking of sth like:

const { page } = useContent<MyType>()
      // ^? MyType

This already works fine for queryContent, e.g. via queryContent<Article>('/articles').

@Barbapapazes
Copy link
Contributor Author

@Barbapapazes I was thinking of sth like:

const { page } = useContent<MyType>()
      // ^? MyType

This already works fine for queryContent, e.g. via queryContent<Article>('/articles').

Yes, that's will be possible!

Copy link
Member

@farnabaz farnabaz left a comment

Choose a reason for hiding this comment

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

Thanks ❀️

@farnabaz farnabaz merged commit 5f059f8 into nuxt:main Sep 18, 2023
7 checks passed
@farnabaz farnabaz mentioned this pull request Sep 26, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants