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

SFC setup error with TS7006 #5347

Closed
mia1024 opened this issue Jan 31, 2022 · 4 comments
Closed

SFC setup error with TS7006 #5347

mia1024 opened this issue Jan 31, 2022 · 4 comments
Labels
has workaround A workaround has been found to avoid the problem scope: types

Comments

@mia1024
Copy link

mia1024 commented Jan 31, 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.

@posva
Copy link
Member

posva commented Feb 1, 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

@posva posva added scope: types has workaround A workaround has been found to avoid the problem labels Feb 1, 2022
@LinusBorg
Copy link
Member

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.

@posva
Copy link
Member

posva commented Feb 1, 2022

Indeed, it works in a vite project too. Closing in favor of vuejs/vue-loader#1915 then

@posva posva closed this as completed Feb 1, 2022
@mia1024
Copy link
Author

mia1024 commented Feb 3, 2022

I think this is a separate issue from vuejs/vue-loader#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.

@github-actions github-actions bot locked and limited conversation to collaborators Oct 4, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
has workaround A workaround has been found to avoid the problem scope: types
Projects
None yet
Development

No branches or pull requests

3 participants