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

An error occurred when using defineProps<>. #4982

Closed
JangCool opened this issue Nov 22, 2021 · 5 comments
Closed

An error occurred when using defineProps<>. #4982

JangCool opened this issue Nov 22, 2021 · 5 comments

Comments

@JangCool
Copy link

Version

3.2.22

Reproduction link

sfc.vuejs.org/

Steps to reproduce

Create one interface file with typescript type.

Import the file from the component(. vue) that definesProps.

Define props as follows.

import type { GroupTitleLargePageData, GroupTitleLargeProps } from "@/interfaces/components/groups/GroupTitleLargePageTypes";

const props = withDefaults(defineProps(),{});

------------------- error ----------------------------

[plugin:vite:vue] [@vue/compiler-sfc] type argument passed to defineProps() must be a literal type, or a reference to an interface or literal type.

D:/project/hamonica/workspace/hamonica-fe-type/src/components/groups/GroupTitleLarge.vu
14 | const props = withDefaults(defineProps(),{});
| ^^^^^^^^^^^^^^^^^^^^

What is expected?

I want to call and use the props interface through import.

What is actually happening?

------------------- error ----------------------------

[plugin:vite:vue] [@vue/compiler-sfc] type argument passed to defineProps() must be a literal type, or a reference to an interface or literal type.

D:/project/hamonica/workspace/hamonica-fe-type/src/components/groups/GroupTitleLarge.vu
14 | const props = withDefaults(defineProps(),{});
| ^^^^^^^^^^^^^^^^^^^^


i use vite + typescript

image

@ygj6
Copy link
Member

ygj6 commented Nov 22, 2021

duplicate of #4294

@ygj6 ygj6 closed this as completed Nov 22, 2021
@ygj6
Copy link
Member

ygj6 commented Nov 22, 2021

look: #4294 (comment) You can declare SampleProps in app.vue
eg:

<script lang='ts'>
export interface SampleProps{
   sample1?:string;
   sample2?:string;
}
</script>

<script setup lang="ts">
import { ref } from 'vue'
  
import SampleProps from './SampleProps'

const props = withDefaults(defineProps<SampleProps>(),{
  sample1:'sample'
});

</script>

<template>
  <h1>{{ props }}</h1>
</template>

@JangCool
Copy link
Author

@ygj6 Okay, I got it. I was told it might be supported later. May I know the schedule?

@peterroe
Copy link

duplicate of #4294

Has it been fixed? I meet the same problem @v3.2.13

@JangCool
Copy link
Author

JangCool commented Mar 28, 2022 via email

@github-actions github-actions bot locked and limited conversation to collaborators Oct 1, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants