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
Typescript's type aliases are not resolved in Vue components #37
Comments
Actually it's funny, my traditional means of doing this is nicer in that all aliases are resolved but considering the |
Would you share your I think this requires some testing with other plugins. |
Hi @qmhc I was just coming back to this issue as I've confirmed that Microsoft has been asked many times about whether The I had a look at your deps and i would appear you're passing the DTS generation over to tsup. I think anything from @egoist is worth building around and I've been meaning to use TSUP a lot more rather than rolling my own configuations but I'm not aware of how TSUP works under the hood and how to ensure that tsc's plugin API is enabled properly. |
I do wonder if maybe this issue needs to be brought over to TSUP as the actual engine for building the declaration files needs to resolve these path aliases either by some means of it's own or by using the containing repo's instance of tsc (as my instance has been patched to use the Typescript plugin API). |
Ok I ran TSUP locally in a repo which doesn't have any Vue components (aka, so the Vue loader isn't needed) and it transpiled perfectly down to a single typed file. However, when I then added this plugin to the same repo it created the types not in a single file but rather in a tree structure which mimics where the types are defined: and then in the files which utilize the path alias it fails, as you can see in this screenshot: |
My configuration files are:
|
I was digging around in your source code and realized that tsup is used to build this plugin but you aren't wrapping it's capabilities into this plugin. Guess that explains why they behave differently 😝 |
Thanks for your research first! This plugin is using After I did some debugging, I found there is a problem in judging whether a path is alias path when alias Currently a workaround is to change the alias config in import path from 'path'
import { defineConfig } from 'vite'
export default defineConfig({
resolve: {
alias: {
'~': path.resolve(__dirname, 'src')
}
}
} |
@qmhc many thanks for looking into this; i'll use the workaround for now. Any sense for when this will be fixed? No pressure, just aware that my own attention is spread quite thinly and want to keep an eye out for it if its relatively soon. |
Great. Many thanks. I did a little reading on ts-morph last night ... looks really useful as my normal experience with AST's has been quite painful. |
In my
tsconfig.json
file I specify the following path alias:And then in a VueJS component I might import a dependencies like so:
Vite compiles the source without issue and
vite-plugin-dts
also creates declaration files but as you can see below, the~/
type alias is still present in the type which makes it unusable as an exported type file.Historically, when using Rollup directly I have used a combination of the
ts-patch
npm module and thetypescript-transform-paths
module:With this done, you just add the plugins to your
tsconfig.json
file like so:This works and I've never found a way to get TYPES to export using the alias Rollup plugin (which is what ViteJS uses I believe). In any case, I'd really like to run everything in ViteJS and your plugin "almost" works ... hoping we can get path aliases incorporated.
The text was updated successfully, but these errors were encountered: