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

types: expose Inject type #7985

Merged
merged 1 commit into from Sep 2, 2020
Merged

types: expose Inject type #7985

merged 1 commit into from Sep 2, 2020

Conversation

Kapcash
Copy link
Contributor

@Kapcash Kapcash commented Aug 28, 2020

Types of changes

  • Bug fix (a non-breaking change which fixes an issue)
  • New feature (a non-breaking change which adds functionality)
  • Breaking change (fix or feature that would cause existing functionality to change)

Description

When using Typescript, I usually declare my Nuxt plugins as so:

import { Context, Plugin } from '@nuxt/types'
const MyPlugin: Plugin = (ctx: Context, inject: (key: string, value: any) => void) => {})

export default MyPlugin

I have to define the inject function type myself. I think it would be better to actually export the existing type!
This way, if the type changes one day, I won't have to change the definition in all my plugins.

Now it looks like:

import { Context, Plugin, Inject } from '@nuxt/types'
const MyPlugin: Plugin = (ctx: Context, inject: Inject) => {})

export default MyPlugin

What do you think?

Checklist:

  • My change requires a change to the documentation.
  • I have updated the documentation accordingly. (PR: #)
  • I have added tests to cover my changes (if not applicable, please state why)
  • All new and existing tests are passing.

@codecov-commenter
Copy link

codecov-commenter commented Aug 28, 2020

Codecov Report

Merging #7985 into dev will not change coverage.
The diff coverage is n/a.

Impacted file tree graph

@@           Coverage Diff           @@
##              dev    #7985   +/-   ##
=======================================
  Coverage   68.87%   68.87%           
=======================================
  Files          91       91           
  Lines        3849     3849           
  Branches     1043     1043           
=======================================
  Hits         2651     2651           
  Misses        972      972           
  Partials      226      226           
Flag Coverage Δ
#unittests 68.87% <ø> (ø)

Flags with carried forward coverage won't be shown. Click here to find out more.


Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 2c600d5...13f417d. Read the comment docs.

@pi0 pi0 changed the title type: add inject function type chore(types): expose inject function type Sep 2, 2020
@pi0 pi0 changed the title chore(types): expose inject function type chore(types): expose Inject type Sep 2, 2020
@pi0 pi0 changed the title chore(types): expose Inject type types: expose Inject type Sep 2, 2020
@pi0 pi0 merged commit ff67179 into nuxt:dev Sep 2, 2020
@pi0
Copy link
Member

pi0 commented Sep 2, 2020

Thanks!

@danielroe
Copy link
Member

@Kapcash Just as a note, you shouldn't need to define the types of the function arguments. This should be equally well-typed:

import { Plugin } from '@nuxt/types'
const MyPlugin: Plugin = (ctx, inject) => {
  // ctx and inject are both typed here...
})

export default MyPlugin

@pi0
Copy link
Member

pi0 commented Sep 2, 2020

@danielroe Agree. Type inference should works too :)

@Kapcash
Copy link
Contributor Author

Kapcash commented Sep 2, 2020

That is very true! Thanks for pointing it out.
Are you still considering merging it? As it's a bit useless actually haha

@pi0
Copy link
Member

pi0 commented Sep 2, 2020

@Kapcash already merged. At least function is internally named now 😊

@Kapcash
Copy link
Contributor Author

Kapcash commented Sep 2, 2020

Could have been reverted as the release is not done yet.
Of course, I'll focus on useful types next time ;)

Thanks for your reactivity on PR by the way!

This was referenced Sep 9, 2020
@danielroe danielroe added the 2.x label Jan 18, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants