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

Using TS generic to cast event target causing "Unterminated JSX contents" error #3598

Closed
nrgnrg opened this issue Apr 13, 2021 · 1 comment
Closed

Comments

@nrgnrg
Copy link
Contributor

nrgnrg commented Apr 13, 2021

Version

3.0.11

Reproduction link

https://codesandbox.io/s/flamboyant-shirley-fy5w6?file=/src/App.vue

Steps to reproduce

Using script setup and a TS generic to react to change events on a select element I get the error "Unterminated JSX contents".

This is the code for the SFC.

<template>
  <select @change="handleChange">
    <option v-for="option in options" :key="option">{{ option }}</option>
  </select>
</template>

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

defineProps<{
  options: string[];
}>();

const handleChange = (e: Event) => {
  console.log((<HTMLSelectElement>e.target).value);
};
</script>

What is expected?

It should compile

What is actually happening?

Internal server error: [@vue/compiler-sfc] Unterminated JSX contents


I think this is a minor bug in the compiler as there are multiple workarounds

const handleChange = (e: Event & { target: HTMLSelectElement }) => {
  console.log(e.target.value);
};

or

const handleChange = (e: Event) => {
  console.log((e.target as HTMLSelectElement).value);
};
@posva
Copy link
Member

posva commented Apr 13, 2021

The cast operator in TS is as and it replaces the version you were using a long time ago. Precisely to avoid ambiguity: https://github.com/Microsoft/TypeScript/wiki/What's-new-in-TypeScript#new-tsx-file-extension-and-as-operator

@posva posva closed this as completed Apr 13, 2021
@github-actions github-actions bot locked and limited conversation to collaborators Oct 22, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants