question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

getCurrentInstance type not correct

See original GitHub issue

Version

2.7.0

Steps to reproduce

vue2.7 getCurrentInstance type was not match vue3 & @vue/composition-api

export function getCurrentInstance(): { proxy: Component } | null {
  return currentInstance && { proxy: currentInstance }
}

see:

What is expected?

has correct type

What is actually happening?

not match

Issue Analytics

  • State:closed
  • Created a year ago
  • Reactions:2
  • Comments:8 (3 by maintainers)

github_iconTop GitHub Comments

5reactions
yyx990803commented, Jul 4, 2022
  1. @vue/composition-api’s implementation is not the source of truth - 2.7 has intentional deviations from it.

  2. Only exposing proxy is intentional, because other properties on the internal instance is considered, well, internal. You should refactor any code that relies on anything other than proxy.

    This is necessary because relying on the internal instance properties when using Composition API is a sign that you are misusing it. It makes your code less reusable AND introduces risk of compatibility with future versions of Vue. We exposed getCurrentInstance mostly for official libraries that need additional internal access, not for userland application code. It was mistakenly documented in WIP v3 docs but is no longer considered a public API.

  3. Vue 3 will likely start showing warnings when you rely on properties other than proxy soon.

3reactions
ulissepresscommented, Aug 9, 2022

@yyx990803 considering that this API is not public, how do you suggest to get the vue app instance (the one created with createApp() ) from any Vue component (created using <script setup>) ?

Currently I was using getCurrentInstance().appContext.app

Read more comments on GitHub >

github_iconTop Results From Across the Web

Vue 3: Is getCurrentInstance() deprecated? - Stack Overflow
Anything you use from that instance can technically break between any release types, since they are not subject to semver constraints.
Read more >
getCurrentInstance in Vue 3 - Special Feature - Program Easily
getCurrentInstance in vue 3 is the special features used to get component instances. It won't work outside setup and lifecycle hooks.
Read more >
API Reference - Vue.js
API Reference · Global API · Composition API · Options API · Built-ins · Single-File Component · Advanced APIs ...
Read more >
Making the most out of Vue.js Injections - Abdelrahman Awad
This is a very important design decision, the return type of inject will always be nullable because there is always a possibility that...
Read more >
Vue 2.7 getCurrentInstance() trying to get properties like $vuetify
I tested it out and it worked for me inside the onMounted callback, which implies that it's just not available before that point,...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found