Subscribe on changes!

An error occurred when using defineProps<>.

avatar
Nov 22nd 2021

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

avatar
Nov 22nd 2021

duplicate of #4294

avatar
Nov 22nd 2021

look: https://github.com/vuejs/vue-next/issues/4294#issuecomment-896082769 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>
avatar
Nov 22nd 2021

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

avatar
Mar 27th 2022

duplicate of #4294

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

avatar
Mar 28th 2022

no. I know it's not supported yet.

-----Original Message----- From: @.> To: @.>; Cc: @.>; @.>; Sent: 2022-03-27 (일) 16:06:49 (GMT+09:00) Subject: Re: [vuejs/core] An error occurred when using defineProps<>. (Issue #4982)

duplicate of #4294

Has it been fixed? I meet the same problem @v3.2.13 — Reply to this email directly, view it on GitHub, or unsubscribe. You are receiving this because you authored the thread.Message ID: @.***>