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

[ADVICE] default as import of defineComponent() has broken typing #3726

Closed
michealroberts opened this issue Nov 10, 2023 · 18 comments
Closed

Comments

@michealroberts
Copy link

michealroberts commented Nov 10, 2023

I just wanted to understand an issue I am seeing, I'm 99% sure it is not Volar throwing any tricks but just wanted to understand the overall reason why a defineComponent is being typed as any.

We have a monorepo setup => whereby the package in question is reliant on vue-demi, the defined component is like:

const Background = defineComponent({
  name: 'Background',
  compatConfig: { MODE: 2 }
  props: {
    ///...all the props
  },
  setup(props: BackgroundProps, { slots }) {
    //...all the setup

    return () => h(
      // ...some rendered element
    )
  },
})

export default Background

This is then exported from the package's entrypoint as:

export { default as Background } from './Background'
// ... other exports here

It's the same if I use the export default directly:

export default defineComponent({ ... })

However, the imported type from a corresponding package seems to be "any":

Screenshot 2023-11-10 at 12 25 05

Does anyone know a trick or something I could do to get this working correctly? 🤔

@so1ve
Copy link
Member

so1ve commented Nov 10, 2023

Hello @michealroberts, are you using javascript not typescript?

@michealroberts
Copy link
Author

@so1ve Hey Ray. TypeScript => the @vue-flow/background package is compiled to js but has the exported types, it's just that they imports are not typed in any way ...

@so1ve
Copy link
Member

so1ve commented Nov 10, 2023

Ah - I see. This is actually a display issue, if you try access some properties such as Background.xxx it should be typed correctly.

@michealroberts
Copy link
Author

@so1ve But on the template, we don't get any type inference from Volar at all. We don't see what props are required or what props are possible ...

@so1ve
Copy link
Member

so1ve commented Nov 10, 2023

Which version are you using? 1.8.22 or 1.8.23?

@michealroberts
Copy link
Author

1.8.22 ...

@michealroberts
Copy link
Author

I basically see this:

Screenshot 2023-11-10 at 15 13 29

@so1ve
Copy link
Member

so1ve commented Nov 11, 2023

Someone told me that 1.8.23 will work, could you please give it a try? Just click install pre-release

@michealroberts
Copy link
Author

Hey Ray, damn - still no luck. The repo uses “shamefully-hoist”, and we’re mixing Vue major versions. Could this be the issue?

@so1ve
Copy link
Member

so1ve commented Nov 12, 2023

Mixing Vue major versions could be the root cause - could you please provide a minimal reproduction to help us investigate? Thanks a lot!

@michealroberts
Copy link
Author

@so1ve Sure -> this MR here on this branch should be enough to investigate: bcakmakoglu/vue-flow#1188

Let me know if you need anything else ...

@michealroberts
Copy link
Author

Hey @so1ve - apologies for bugging, but I wondered if you managed to look at this?

@so1ve
Copy link
Member

so1ve commented Nov 16, 2023

Sorry, missed your reply 🥹 I'll check it now

@so1ve
Copy link
Member

so1ve commented Nov 16, 2023

image

Everything is working fine on my side 🤔

@michealroberts
Copy link
Author

Cool, is that inside the project? Looks to be working well ...

@michealroberts
Copy link
Author

@so1ve What is your setup? Volar seems to complain for me regarding @vue/runtime-core:

Vue 2.7 already includes JSX type definitions. You can remove the @vue/runtime-dom dependency from package.json.

@so1ve
Copy link
Member

so1ve commented Nov 16, 2023

I simply cloned the repository, checkout your PR, and then build the types.

I use Vue Language Tools 1.8.23

@michealroberts
Copy link
Author

@so1ve Could you double check this for me, I'm not convinced because the current master branch works but that PR doesn't. I am using Vue Language Tools 1.8.23 pre-release and I have built the types but I am not seeing any type hints at all.

@michealroberts michealroberts closed this as not planned Won't fix, can't repro, duplicate, stale May 25, 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