Subscribe on changes!

SFC setup error with TS7006

avatar
Jan 31st 2022

Version

3.2.29

Reproduction link

github.com

Steps to reproduce

  • Clone the repository
  • Run yarn
  • Run yarn build

What is expected?

No error is produced

What is actually happening?

The compilation process errors with TS7006: Parameter 'n' implicitly has an 'any' type.


This bug seems to only happen if the SFC contains a <script lang="ts" setup>, some Typescript code or comments, at least 2 elements (or lines of comments) in templates, and scoped css. This error is independent of vuejs/vue-loader#1915 because the error caused by the issue can be avoided by setting "strictPropertyInitialization": false in tsconfig.json, which is indeed the case here.

avatar
Feb 1st 2022

In general, having all TS strict options activated (through strict: true without deactivating any) is a good idea. Some types require this to avoid loosing up some types and making them any

avatar
Feb 1st 2022

I rather suspect the issue with with a limitation of ts-loader, as described in the new docs:

https://staging.vuejs.org/guide/typescript/overview.html#note-on-vue-cli-and-ts-loader

ts-loader can only type check post-transform code.

Doing typechecking with vue-tsc works fine in the provided repo. I just think ts-loader fails to do a proper typecheck here as it is missing type infromation that vue-tsc has - because the former analyses the code post-transform of <script setup> where vue-tsc analyses the SFC as-is.

avatar
Feb 1st 2022

Indeed, it works in a vite project too. Closing in favor of https://github.com/vuejs/vue-loader/issues/1915 then

avatar
Feb 3rd 2022

I think this is a separate issue from https://github.com/vuejs/vue-loader/issues/1915 because the workaround that applies to the issue doesn't apply here.

Also, is there a way to add a switch so that the generated TS code can have a // @ts-ignore above line 4 to avoid the error? The documentations linked only mentioned migrating to vite, which isn't quite an option for projects using manually configured webpack instead of vue-cli, as there are many other dependencies on webpack in the projects.