I just wanted to create a Vue 3 app with TypeScript
I did this:
npm create vue@latest
In the following process, I enabled TypeScript and the router. I get a component called HelloWorld
, where I replace the <script></script>
stuff by this:
<script lang="ts">
import { defineComponent } from 'vue'
export default defineComponent({
props: {
msg: String
},
setup(props) {
props.message // <-- type: string
},
methods : {
handleClick(x: number){
console.log("x=" + x);
}
}
})
</script>
In the template, I add these two buttons
<button @click="handleClick(16)">Click me</button>
<button @click="handleClick('Amen')">Click me</button>
For the second one, I get no error message, although the argument of handleClick must be a number. Clicking on the second button also works, it prints x=Amen
Why does the TypeScript support not work?