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

Typescript conditional checks seem to fail on v-for (vite, vue-ts, vue-tsc) #1312

Closed
waldi opened this issue May 18, 2022 · 1 comment
Closed
Labels
bug Something isn't working

Comments

@waldi
Copy link

waldi commented May 18, 2022

image

When checking for a variable being null using v-if, the check does not seem to follow through to v-for elements.

Error:

Type 'string | null' is not assignable to type 'string'.
  Type 'null' is not assignable to type 'string'.ts(2322)
HelloWorld.vue(1, 1): The expected type comes from property 'foo' which is declared here on type 'IntrinsicAttributes & Partial<{}> & Omit<Readonly<ExtractPropTypes<__VLS_TypePropsToRuntimeProps<{ msg: string; foo: string; }>>> & VNodeProps & AllowedComponentProps & ComponentCustomProps, never>'

Example Code:

App.vue

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

const msgs = ["Msg 01", "Msg 02", "Msg 03"];

const foo = ref<string | null>("Foo");
</script>

<template>
  <template v-if="foo">
    <HelloWorld v-for="msg in msgs" :msg="msg" :foo="foo" />
  </template>
</template>

HelloWorld.vue

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

defineProps<{ msg: string; foo: string }>();

const count = ref(0);
</script>

<template>{{ msg }} - {{ foo }}</template>

<style scoped></style>

package.json

{
  "name": "vue-ts-bug",
  "private": true,
  "version": "0.0.0",
  "scripts": {
    "dev": "vite",
    "build": "vue-tsc --noEmit && vite build",
    "preview": "vite preview"
  },
  "dependencies": {
    "vue": "^3.2.25"
  },
  "devDependencies": {
    "@vitejs/plugin-vue": "^2.3.3",
    "typescript": "^4.5.4",
    "vite": "^2.9.9",
    "vue-tsc": "^0.34.7"
  }
}
@johnsoncodehk johnsoncodehk added the bug Something isn't working label May 18, 2022
@johnsoncodehk
Copy link
Member

johnsoncodehk commented May 18, 2022

Thanks for the report! This is regression from v0.34.15, you could use v0.34.14 for now.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants