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

augmenting $route on ComponentCustomProperties #2341

Closed
danielroe opened this issue Aug 15, 2024 · 1 comment
Closed

augmenting $route on ComponentCustomProperties #2341

danielroe opened this issue Aug 15, 2024 · 1 comment

Comments

@danielroe
Copy link
Member

danielroe commented Aug 15, 2024

Reproduction

https://www.typescriptlang.org/play/?#code/JYWwDg9gTgLgBAbzgcwKYwMIFcpVQOxgEl8BnGAQ3wGNU4BfOAMyghDgHIA3LVDgKH5MsNGMAj44wUgDkIMAIL4AngAowrMAC445KMHzIAlInqC0mHHkIlyVWqqMBCAHQUwYDBJioAHjBdqCSZgZBdkABsIACMKCIAFTVRYYFRSFwASViwfF2EIhIoYAAt+AHoyuAABGFIAWj8wVGoYBtxoFHRsXAJiMkoaVEdXd09vPwCg-BCwyJi4xIgmlLTM7J9+aTlFFVULbus+u0Hhtw8vQgnA4NDwqNiEpJX0rIgc1CN+IA

Steps to reproduce the bug

See that getCurrentInstance()!.appContext.config.globalProperties.$route is typed as any.

Expected behavior

This type should be augmented.

Actual behavior

It is not.

Additional information

The reason this is occurring is that the type getCurrentInstance()!.appContext.config.globalProperties returns is based on the ComponentCustomProperties interface exposed from @vue/runtime-core, not the version exposed from vue. So augmenting vue's interface does not affect the type returned from getCurrentInstance.

This means that the documentation on https://vuejs.org/api/utility-types.html#componentcustomproperties is probably incorrect. (Or we need to modify the code in @vue/runtime-core to import an interface from vue.

resolves nuxt/nuxt#28373

Copy link
Member

posva commented Aug 15, 2024

Closing for the moment as discussed with Daniel, the repro is missing importing from vue-router and that fixes it:

import { getCurrentInstance } from 'vue'
import {} from 'vue-router'

function isNotAny(prop: string) {}

getCurrentInstance()!.appContext.config.globalProperties.$route.fullPath
// @ts-expect-error getCurrentInstance()!.appContext.config.globalProperties.$route
isNotAny(getCurrentInstance()!.appContext.config.globalProperties.$route)```

@posva posva closed this as not planned Won't fix, can't repro, duplicate, stale Aug 15, 2024
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

2 participants