-
-
Notifications
You must be signed in to change notification settings - Fork 416
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
Default export of the module has or is using private name 'Props' #1232
Comments
Hi @hayabusa2009, try remove <script lang="ts">
//step1: declear type
interface Props {
foo: string;
}
</script>
<script lang="ts" setup>
// setp2: defineProps
defineProps<Props>();
</script> |
Why Volar is complaining about the interface anyway? |
@mobayen You just need move interface from ...
setup() {
interface Props {
foo: string;
}
} |
@johnsoncodehk thank you for your replay and I try your advices but failed. <script lang="ts" setup>
import type { ModalProps } from 'third-part-library/Modal';
interface Props extends ModalProps {
visible: boolean;
}
const props = defineProps<Props>();
</script> |
@hayabusa2009 Have you try move <script lang="ts">
import type { ModalProps } from 'third-part-library/Modal';
interface Props extends ModalProps {
visible: boolean;
}
</script>
<script lang="ts" setup>
const props = defineProps<Props>();
</script> |
@johnsoncodehk when remove |
Life savier, ty very much! |
@johnsoncodehk With the latest version, this is blowing up the IDE. According to the documentation:
and it also gives a code example of it in the script setup documentation: interface Props {
msg?: string
labels?: string[]
}
const props = withDefaults(defineProps<Props>(), {
msg: 'hello',
labels: () => ['one', 'two']
}) I believe it should not throw here based on vue's documentation. Would you be willing to agree and would you like me to open an issue for it? |
Hi, I found a lighter alternative to moving the interfaces: exporting them also works with Volar 0.38.1. <script lang="ts" setup>
export interface Props {
msg?: string
labels?: string[]
}
const props = withDefaults(defineProps<Props>(), {
msg: 'hello',
labels: () => ['one', 'two']
})
</script> But I totally agree with @buckeyez. Volar should comply with Vue, and not the other way around. |
removing declaration from tsconfig.json file works for me |
This is not a valid solution. Its fine if what you are building is the end all, but when building components and libs it would defeat the purpose of using TS to not have the declarations for consumers. |
Hi, what is the current recommended way to use interface for props? It didn't work having it in a separate script, I get varying errors: I have "Vue Language Features (Volar)" v0.40.13 |
Hello, I have same issue when try to build in lib mode |
Can you provide a minimal reproduction code? |
I will try to describe the problem in more detail. I have a small component library. Vue 3 + TS + Vite.
In tsconfig.json
In vite.config.ts
Example of component: <template>
<div v-show="active" class="tab">
<slot />
</div>
</template>
<script lang="ts">
import { IEvent } from "@/components/types";
export interface ISvTabProps {
title: string;
id: string;
actions?: IEvent[];
hidden?: boolean;
parentId?: number;
}
</script>
<script setup lang="ts">
import { ComponentInternalInstance, getCurrentInstance, ref } from "vue";
const props = withDefaults(defineProps<ISvTabProps>(), {
hidden: false,
});
... // some code stuff
</script> Build script in package.json
When I run the vue-tsc, everything works fine and the When I run the build script I get the following error:
|
My error had to do with Vitest: if I choose vitest when installing (
I tried to change stuff in those three files, but didn't manage to get rid of the errors.
Here is a reproduction |
Create some reproduction repo |
Maybe all the same it's not in the library but in Vue itself |
Putting them in separate <script> tags lets them be excluded from the type definition for the component. See the error when creating types (e.g. `pnpm vue-tsc --composite false -p tsconfig.app.json --declaration --emitDeclarationOnly`; note that this will generate *.d.ts files next to the source files), and this comment: <vuejs/language-tools#1232 (comment)>
Same problem here. I discovered it when using the new reactivity transform feature. It is also worth noting that this is IDE error only. Compiler doesn't complain and everything works as expected. Can be solved by exporting the interface, but that doesn't seem right to me since no export is used in Vue docs. |
The error is throw by |
I can only got
|
@StepanMynarik could you provide repro case? |
Why is this closed? Based on how Vue 3 outlines how to use Littering a project with
Apologies for coming off rude, but workarounds doesn't constitute closing an issue. |
I agree with this, the plugin isnt working how the docs say it should work ..? |
A workaround is to annotate <template>test</template>
<script lang="ts" setup>
type Props = { // <----- Use type instead of interface
foo: string;
}
defineProps<Props>();
</script> Works in Volar |
Existing code snippet gives this error: Default export of the module has or is using private name 'Props'.ts (4082) Error fixed thanks to: vuejs/language-tools#1232 (comment)
Existing code snippet gives this error: Default export of the module has or is using private name 'Props'.ts (4082) Error fixed thanks to: vuejs/language-tools#1232 (comment)
Existing code snippet gives this error: Default export of the module has or is using private name 'Props'.ts (4082) Error fixed thanks to: vuejs/language-tools#1232 (comment) Co-authored-by: riz <[email protected]>
Same here! |
Hey guys - for those who subscribes this issue - this is likely a limitation in Typescript. interface Foo {
foo: 1
}
// No error! Foo has been extended
interface Foo {
bar: 1
}
// -------
type Bar = {}
// Oops, error!
type Bar = {} Why In looking for a doable solution and I can implement it in a PR. Any help is appreciated! |
Please reopen this issue. Having it closed sends the wrong message, and motivates folks to open new issues for the same topic. My issue is the same as described above: I can't define I don't seem to be able to ignore this error with And this is a library of components. |
It really doesn't make the best sense to close the issue if the docs say one thing and the plugin faults the same thing. It's very confusing to follow what you think is convention then get dinged for it and use work arounds. |
@frankypixels Any reproduction? I can't reproduce this issue anymore. |
This is exactly that I had yesteday
|
It worked for me after updating volar to pre-release version 1.8.23 |
Starting from a certain version, when there is only one script setup block, the setup code will be generated to the file root instead of the function scope to avoid this problem. |
2.1.4 - still actual. But with defineComponent syntax. UPD: <script setup lang="ts" generic="T">
export interface Props<T> |
I created a repository to demonstrate the issue where a Repository: https://github.com/charnog/vue-default-export We initially started our project using only the This might also be related to @mityaua’s issue, but I’m not entirely sure. @KazariEX @johnsoncodehk let me know if you’d like me to create a distinct issue for this. |
if u use export props it works: charnog/vue-default-export#1 |
@webdesignberlin Yep, thank you! This “workaround” was already described here. There’s also the My question isn’t about “how to fix it in a component” but rather “what is the best approach and is it possible to address this in volar/vue-tsc?” If not, then what should be considered the official approach? |
This is a limitation of TS. // setup.ts
import { defineComponent } from "vue";
interface Props {
msg: string;
}
export default defineComponent({
__typeProps: {} as Props
}); // define.ts
import { defineComponent } from "vue";
import Setup from "./setup";
export default defineComponent({
components: {
Setup,
},
}); The currently discovered solution that can be implemented in this repository is: export default defineComponent({
__typeProps: {
...{} as Props
}
}); |
@charnog please feel free to open a new issue. |
when upgrade volar to ^0.34.9 , there is a ts warning
Default export of the module has or is using private name 'Props'
at the top of templatebut if definePorps like below, the warning disappear
The text was updated successfully, but these errors were encountered: