Skip to content

<script setup>: Prop Member "Args.Post" is conflicting with "Post" import from PostDef.ts #4758

Closed
@phasetri

Description

@phasetri

Version

3.2.19

Reproduction link

sfc.vuejs.org/

Steps to reproduce

yarn global add @vue/cli
vue create my_project

Select these options when prompted:

? Please pick a preset: Manually select features
? Check the features needed for your project: Choose Vue version, Babel, TS, Router, Vuex, CSS Pre-processors
? Choose a version of Vue.js that you want to start the project with 3.x
? Use class-style component syntax? No
? Use Babel alongside TypeScript (required for modern mode, auto-detected polyfills, transpiling JSX)? Yes
? Use history mode for router? (Requires proper server setup for index fallback in production) Yes
? Pick a CSS pre-processor (PostCSS, Autoprefixer and CSS Modules are supported by default): Sass/SCSS (with dart-sass)
? Where do you prefer placing config for Babel, ESLint, etc.? In dedicated config files
? Save this as a preset for future projects? No
cd my_project
cd src/components
touch PostDef.ts
touch PostFc.vue

Content of PostDef.ts:

export interface Post {
  Message: string; 
}

Content of PostFc.vue:

<script setup lang="ts">

import {
  Post,
} from "./PostDef";

interface Props {
  Args: {Post: Post};
}
const props = withDefaults(defineProps<Props>(), {});
</script> 

<template>
  {{Args.Post}}
</template>

Within the auto-generated HelloWorld.vue, add a PostFc instance anywhere on the page

<script lang="ts">
import { defineComponent } from 'vue';
import PostFcVue from './PostFc.vue';

export default defineComponent({
  name: 'HelloWorld',
  props: {
    msg: String,
  },
  components: {
    PostFc: PostFcVue
  }
});
</script>

<template>
      ...
      ...
      ...
      <li><a href="https://github.com/vuejs/awesome-vue" target="_blank" rel="noopener">awesome-vue</a></li>
    </ul>
    <PostFc :Args="{Post: {Message: 'Hello World!!!'}}"></PostFc>
  </div>
</template>

Then run the app:

yarn 
yarn serve

What is expected?

No warnings should be reported when yarn serve finishes compiling the app.

What is actually happening?

When yarn serve finishes compiling the app, it will report a warning that PostDef.ts does not have a reference to Post:

warning  in ./src/components/PostFc.vue?vue&type=script&setup=true&lang=ts

"export 'Post' was not found in './PostDef'

Note that the warning is not visible in the reproduction link; you have to reproduce it on your local machine.


I was able to reproduce the same problem by creating a Vite project instead of Vue-CLI project.

The problem is particularly serious in Vite as the warning gets reported on the browser console, and cause the whole HelloWorld page to not load at all.

You can quickly make the warning go away by modifying the template in PostFc.vue such that {{Args.Post}} does not reference Post at all --- for example: {{Args}}

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions