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

TypeError when using ternary operator in <component> #2725

Closed
ymy0622 opened this issue Apr 27, 2023 · 4 comments
Closed

TypeError when using ternary operator in <component> #2725

ymy0622 opened this issue Apr 27, 2023 · 4 comments
Labels
bug Something isn't working good reproduction ✨ This issue provides a good reproduction, we will be able to investigate it first

Comments

@ymy0622
Copy link

ymy0622 commented Apr 27, 2023

<script setup lang="ts">
import { ref } from 'vue';

const flag = ref(true);
</script>

<template>
  <div>
    <Component :is="flag ? 'ComA' : 'ComB'" />
    <Component :is="!flag ? 'ComA' : 'ComB'" style="background: pink" />
  </div>
</template>

ComA & ComB are global registration

image

Repro repo: https://stackblitz.com/edit/vitejs-vite-uonfzg?file=package.json

@jiikoosol
Copy link

I have the same problem.

@lihanspace
Copy link

image

@jiikoosol
Copy link

In my case this was the solution. So basically I had to define the returning type of the computed property which is used to define the dynamic component type. It also works with as any or just as Component.

<template>
  <component :is="myComponent"></component>
</template>

<script setup lang="ts">
import { computed, ref, type Component } from "vue";
import type MyComponent from "@/components/MyComponent.vue";

const someCondition = ref(true);

const myComponent = computed(() =>
  someCondition.value ? "my-component-name" : undefined
) as Component<typeof MyComponent>;
</script>

@lihanspace
Copy link

I have rolled back the version of vue-tsc to v1.5.2

@johnsoncodehk johnsoncodehk added bug Something isn't working good reproduction ✨ This issue provides a good reproduction, we will be able to investigate it first labels Apr 27, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working good reproduction ✨ This issue provides a good reproduction, we will be able to investigate it first
Projects
None yet
Development

No branches or pull requests

4 participants