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(kit): addTypeTemplate helper with auto-registration #21331

Merged
merged 12 commits into from
Jun 9, 2023

Conversation

Hebilicious
Copy link
Member

@Hebilicious Hebilicious commented Jun 2, 2023

πŸ”— Linked issue

❓ Type of change

  • πŸ“– Documentation (updates to the documentation, readme or JSdoc annotations)
  • 🐞 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)
  • 🧹 Chore (updates to the build process or auxiliary tools and libraries)
  • ⚠️ Breaking change (fix or feature that would cause existing functionality to change)

πŸ“š Description

This PR adds an addTypes utility to @nuxt/kit.
It also improves the documentation section regarding adding types, by including a general usecase for addTemplate and documented an use-case of updateTemplate.

πŸ“ Checklist

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

@nuxt-studio
Copy link
Contributor

nuxt-studio bot commented Jun 2, 2023

βœ… Live Preview ready!

Name Edit Preview Latest Commit
Nuxt Docs Edit on Studio β†—οΈŽ View Live Preview 33f22e0

@danielroe danielroe requested a review from lihbr June 8, 2023 08:34
@danielroe danielroe added this to the v3.6 milestone Jun 8, 2023
@danielroe danielroe changed the title feat(kit): add types functionality feat(kit): addTypeTemplate helper with auto-registration Jun 9, 2023
@danielroe danielroe merged commit ee6869b into nuxt:main Jun 9, 2023
23 checks passed
@github-actions github-actions bot mentioned this pull request Jun 9, 2023
const template = addTemplate(_template)

if (!template.filename.endsWith('.d.ts')) {
throw new Error(`Invalid type template. Filename must end with .d.ts : "${template.filename}"`)
Copy link
Member Author

Choose a reason for hiding this comment

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

I avoided doing it like this, because this can throw while the template is written. Is this behaviour fine?


#### Adding Type Declarations

You might also want to add a type declaration to the user's project (for example, to augment an Nuxt interface
Copy link
Member Author

Choose a reason for hiding this comment

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

to augment an Nuxt interface => to augment a Nuxt interface


You might also want to add a type declaration to the user's project (for example, to augment an Nuxt interface
or provide a global type of your own). For this, Nuxt provides the `addTypeTemplate` utility that both
writes a template to disk and adds a reference to it in the generated `nuxt.d.ts` file that.
Copy link
Member Author

Choose a reason for hiding this comment

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

writes a template to the disk ?

@Hebilicious
Copy link
Member Author

@danielroe I forgot to click submit review 🀦🏽 I can open another PR for the typos

@danielroe
Copy link
Member

Thank you 😊

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.

None yet

2 participants