Skip to content

Commit

Permalink
fix(types): use declare module vue
Browse files Browse the repository at this point in the history
This has been the recommended approach for a while and supports more cases. See https://vuejs.org/guide/typescript/options-api.html#augmenting-global-properties for more information
  • Loading branch information
posva committed May 17, 2023
1 parent b041c15 commit b7f97dd
Showing 1 changed file with 1 addition and 1 deletion.
2 changes: 1 addition & 1 deletion packages/pinia/src/globalExtensions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ declare module 'vue/types/options' {
}

// @ts-ignore: works on Vue 3, fails in Vue 2
declare module '@vue/runtime-core' {
declare module 'vue' {
export interface ComponentCustomProperties {
/**
* Access to the application's Pinia
Expand Down

1 comment on commit b7f97dd

@ByScripts
Copy link

@ByScripts ByScripts commented on b7f97dd May 18, 2023

Choose a reason for hiding this comment

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

@posva

I have some concerns about this change. When using declare module 'vue', then $pinia is no longer available in template.

Property '$pinia' does not exist on type '{ $: ComponentInternalInstance; $data: {}; ...

Some times ago, a similar change has been made in vue-router@4

Now, using $route and $router in Vue Template throw the same error.

I'm using Composition API and the given URL is about Options API so I don't know if it's related.

The problem exists in Vue 3.2 and 3.3

Edit: vue-i18n still uses declare '@vue/runtime-core' and $t is available in template. If I change it to declare 'vue' the same problem happens.

Please sign in to comment.