-
-
Notifications
You must be signed in to change notification settings - Fork 8.3k
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
script-setup: Types need to be imported separately with import type ....
#3183
Comments
It's a Bug in the compiler that doesn't differentiate between type exports and runtime exports. As a workaround, you can use |
Is it related to vite? vitejs/vite#1661 |
Don't think so, that issue revolved around runtime exports ( There were also comments about the problem with Type exports in the RFC comments that found the same solution/workaround: |
Oh, the code it generates looks like this: import {Ref} from 'vue'
export default {
expose: [],
setup(__props) {
return { Ref }
}
} But I can't find any way other than list all types through enumeration, or we can consider imports beginning with capital letters as types, but exclude such things as |
Yeah, don't think that would be a reliable heuristic. I don't think the compiler can reliably determine wether or not an import is a Type or a runtime object, so in theory we would have to clean up the imports with Ts somehow before generating the code. No idea if something like this is even feasable, not really familiar enough with compiler details. Should we consider this an enhancement rather than a bug as |
Agree |
import type ....
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
I rethinked this with #3249. Why do we need to expose the imports from <script setup>
import { Teleport } from 'vue'
</script> output: export default {
expose: [],
setup() {
return { Teleport }
}
} So we only need a whitelist: |
For Types the import type solution worked for me. But I cant get interfaces working. I always get the warning, that the interface is not exported. "export 'Consultation' was not found in '@/libs/shared/interfaces/consultation' |
I think compiler has no a perfect way to solve this problem, but IDE already report error for this use case, so maybe we don't need to do anything in compiler side. |
This impacts types, which you can work-around by using One solution to this problem could be to check what is actually used by the template and not export identifiers that it doesn't use.
I believe none of this is an issue when building for production and the template becomes a lambda inside the setup code, which simply has local scope automatically captured. That's actually great and the best solution, the only issue is that the other way is used in dev to enable HMR / exposing state to dev tools. I wonder if we could figure out a way to do those things with the lambda design instead... (I don't have an idea just yet 🤔) |
@yyx990803 it's fantastic you could fix that! |
Version
3.0.5
Reproduction link
https://github.com/JSerFeng/bug/blob/master/src/App.vue
Steps to reproduce
<script setup lang="ts"> import {Ref} from "vue" </script>What is expected?
nothing happens
What is actually happening?
Uncaught SyntaxError: The requested module '/node_modules/.vite/vue.js?v=6cc5afeb' does not provide an export named 'Ref'
The text was updated successfully, but these errors were encountered: