Using TypeScript in Nuxt or Vue can be so complex. I only want to do type checking! Nothing more. It took me so long to find out how to enable type checking in Nuxt, so I will share what I discovered (and you can apply these findings in Vue too).
It should have been obvious. In the initial web days, we had to set the script tag’s language to JavaScript explicitly. JavaScript was not the default language in the early days. Since then, the browser now assumes the script tag is always JavaScript.
To enable TypeScript in the .vue
page, change the script language.
<script lang="ts">
const myVar: string = 'hello'
</script>
We can now use TypeScript. Simple.
#typescript #javascript #nuxt #vue #programming