vuejs / vue-loader

📦 Webpack loader for Vue.js components
MIT License
4.99k stars 915 forks source link

TypeScript with noImplicitAny: true and SFC without script tag #2074

Open Ixonal opened 6 months ago

Ixonal commented 6 months ago

Soooo this is a pretty obscure issue I found. I have a project that's using TypeScript, and I want to turn on the noImplicitAny option. When I do so, compilation fails on any single file components that don't have a script setup block with lang set to "ts" and some form of content (even if just comments). This seems to be because the parameters to the generated render function lack types. I'm guessing the lang part of things is what notifies vue to generate the types, and empty tags are pruned before the lang attribute is seen. Is there some way to notify the plugin that all loaded script tags will be typescript? Or do I need to add the redundant script tag to every component that doesn't have behavior?

Here's an example of what I'm talking about

<script setup lang="ts">
  //this is required if we're to have noImplicitAny: true
  //both the lang being set to ts and these comments are needed
  //for the emitted code to have types associated with parameters
</script>

<template>
  <h1 class="text-primary fw-bold text-center border-bottom border-primary pt-3 pb-3">
    <slot></slot>
  </h1>
  <div class="pb-3"></div>
</template>