withastro / language-tools

Language tools for Astro
MIT License
272 stars 54 forks source link

🐛 BUG: Vue types imported from monorepo package are not regonized #674

Open minht11 opened 1 year ago

minht11 commented 1 year ago

Describe the Bug

I have monorepo, with two packages one is vue components and other regular astro site. I use project references and so on. Importing regular ts/tsx files inside astro pages work as expected, but when I try importing any of my vue components, types are not resolved correctly. If i reexport vue components to index.ts and then import that, it shows that such export exists but types are empty. Actual vue component runs, just types are wrong.

Semi related to https://github.com/withastro/language-tools/issues/649 but I don't do any bundling/dts emit so it is bit different.

Steps to Reproduce

  1. Setup monorepo with 2 packages. One vue components, other regular astro site.
  2. Try to import component from vue package, into astro site.
  3. Observe types being not recognized.
Princesseuh commented 1 year ago

Any chance you could share a reproduction?

minht11 commented 1 year ago

You should be able reproduce issue here https://github.com/minht11/astro-monorepo-types-issue

minht11 commented 1 year ago

I installed volar extension to see virtual files for vue components in design-system package and they are empty, because of this line https://github.com/withastro/language-tools/blob/7e5ccb70a59b0449048295b24e8cb4742063f6b0/packages/language-server/src/core/utils.ts#L17-L23

As far as I understand astro resolves entry point for design-system not for site package, it doesn't find @astro/vue integration installed there so it returns empty file.

In fact if I add "@astrojs/vue": "^3.0.1" to design-system package.json it starts to work.

codethief commented 4 months ago

@Princesseuh Just found my way here through Google. Could you comment on the state of support for TSC project references in astro check? I have been trying to get Astro to correctly type-check .astro files which import files from other projects but it either complains about those files not existing (if I use astro check --tsconfig tsconfig.astro.json) or it ignores those imports entirely & fails to recognize type errors (if I use astro check --tsconfig tsconfig.json, where tsconfig.json is the "main" aka "solution-style" tsconfig that references everything else). I'll be happy to file a bug report but first I wanted to check what to expect and whether I'd need to create minimal example at all that reproduces my issues. (For instance, the people over at moonrepo also report that astro check does not work with project references.)

On a more general note, it'd be great if the docs went into a bit more detail on what astro check & the language server it uses actually do. (Do they use TSC under the hood? What TSC features are supported? etc.)

Princesseuh commented 4 months ago

I don't know exactly the features that are supported, astro check is a pretty thin wrapper around @volarjs/kit, which uses the TypeScript APIs directly to get errors (this is similar to vue-tsc works, if you're familiar with that)

codethief commented 4 months ago

I see, thank you! The thing is that vue-tsc works well with project references, so now I'm surprised that astro check behaves differently. :\

codethief commented 4 months ago

If I file a bug report, I suppose I should file it here in this repo then?

Princesseuh commented 4 months ago

If I file a bug report, I suppose I should file it here in this repo then?

I think the issue is ultimately upstream, but you may fill it here for convenience and I'll report it upstream (either way, I'm a maintainer of both projects so...)

vue-tsc only somewhat works like this, it uses fairly different codepaths mostly because it does other things