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

[2.7.x] [typescript] Type augmentation does not work #12642

Closed
last-partizan opened this issue Jul 8, 2022 · 4 comments
Closed

[2.7.x] [typescript] Type augmentation does not work #12642

last-partizan opened this issue Jul 8, 2022 · 4 comments

Comments

@last-partizan
Copy link

Version

2.7.4

Reproduction link

github.com

Steps to reproduce

look at the example repo, or, install vue@2.7.4 and add type augmentation:

// env.d.ts
declare module "vue/types/vue" {
  interface Vue {
    $t: (s: string) => string
  }
}
// broken-augment.ts
import {defineComponent} from "vue";

export default defineComponent({
  methods: {
    getTranslatedText() {
      return this.$t("hello.vue");
    },
  },
});

What is expected?

Expected no erros.

What is actually happening?

> pnpm vue-tsc
src/broken-augment.ts:6:14 - error TS2571: Object is of type 'unknown'.

6       return this.$t("hello.vue");
               ~~~~~~~


Found 1 error in src/broken-augment.ts:6
@jhxxs
Copy link

jhxxs commented Jul 25, 2022

vue 2.7.8 still has this problem

image

@last-partizan
Copy link
Author

last-partizan commented Jul 25, 2022

That's strange.

In my production code this is indeed resolved, but in my minimal example: https://github.com/last-partizan/vue-examples/tree/692569fa503c0511cd10d771432222980b6afc49

There still a problem after updating to 2.7.8.

Fixed by adding export {}

@jhxxs
Copy link

jhxxs commented Aug 11, 2022

vue 2.7.8 still has this problem

image

sorry, my bad, turns out i forget to add

export {}

at last line

@axetroy
Copy link

axetroy commented Apr 7, 2023

vue 2.7.14 still has this problem

import Vue from 'vue'

// not working
declare module 'vue/types/vue' {
    export interface Vue {
        test(): void
    }

    export interface VueConstructor {
        test(): void
    }
}

// Here is my solutoin
// works with defineComponent()
declare module 'vue/types/v3-component-options' {
    export interface MethodOptions {
        test(): void
    }
}

export {}

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

No branches or pull requests

3 participants