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

type guard on <template> for a named slot is not recognized #625

Closed
schl3ck opened this issue Oct 21, 2021 · 6 comments
Closed

type guard on <template> for a named slot is not recognized #625

schl3ck opened this issue Oct 21, 2021 · 6 comments
Labels
bug Something isn't working good reproduction ✨ This issue provides a good reproduction, we will be able to investigate it first upstream

Comments

@schl3ck
Copy link

schl3ck commented Oct 21, 2021

When a type guard is used on a <template> for a named slot (also the default slot), then it is not recognized in the slot content.

A simple example:

<template>
  <MyComponent>
    <template v-if="status" #default>
      {{ status.message }}
    </template>
  </MyComponent>
</template>

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

const status = ref<{ message: string } | undefined>();
loadStatus();
async function loadStatus() {
  // load it from somewhere
}
</script>

This example assumes that MyComponent exists and behaves differently depending on if the default slot is available or not. Because of this the v-if can't be moved anywhere else.

TypeScript complains though that status in {{ status.message }} can be undefined. Duplicating the template element without #default solves the issue but looks odd in the template and serves no other pupose.

@johnsoncodehk
Copy link
Member

Thanks for the report, this is a similar problem to vuejs/core#3498.

@johnsoncodehk johnsoncodehk added bug Something isn't working upstream labels Oct 22, 2021
@NateScarlet
Copy link

NateScarlet commented May 11, 2022

This seems been fixed in 0.34.9 (or earlier), but come back again in 0.34.12

@johnsoncodehk
Copy link
Member

@NateScarlet we have never fix this. 😅 I guess your case it is a side effect by fixed #1264.

@mdoesburg
Copy link

@johnsoncodehk Can/will this be fixed? Can you make a "special case" fix for this as suggested here: vuejs/core#3498 (comment)

@johnsoncodehk
Copy link
Member

@johnsoncodehk Can/will this be fixed? Can you make a "special case" fix for this as suggested here: vuejs/core#3498 (comment)

We can't because the situation is much more complicated.

@johnsoncodehk
Copy link
Member

We refactored the template codegen and now find a simple workaround.

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 upstream
Projects
None yet
Development

No branches or pull requests

4 participants