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

Unexpected type errors with vue-tsc 2.0.10 #4218

Closed
kingychiu opened this issue Apr 5, 2024 · 6 comments
Closed

Unexpected type errors with vue-tsc 2.0.10 #4218

kingychiu opened this issue Apr 5, 2024 · 6 comments
Labels
duplicate This issue or pull request already exists good reproduction ✨ This issue provides a good reproduction, we will be able to investigate it first need info

Comments

@kingychiu
Copy link

Run

npm install
npx nuxi typecheck

in the following example:

https://stackblitz.com/edit/nuxt-starter-whhd9d?file=package.json

with vue-tsc 2.0.10:

Found 3 errors in 2 files.

Errors  Files
     2  app.vue:16
     1  node_modules/nuxt-time/dist/runtime/components/NuxtTime.vue:3

With vue-tsc 2.0.7: No errors

The first error is from this block of code:

<div v-if="myState?.arrayState" class="wrapper">
  <button @click="handle(myState.arrayState[0])">Add</button>
</div>

In vue-tsc 2.0.10, it raises an error about "myState.arrayState" is possibly undefined, but it is checked by the v-if already.

The second error comes from a node_module, which should be ignored.

Full error log from vue-tsc 2.0.10:

~/projects/nuxt-starter-whhd9d 35s
❯ npx nuxi typecheck
ℹ Compiled plugins/server.mjs in 3246.79ms                           01:31:04
ℹ Compiled types/plugins.d.ts in 3684.89ms                           01:31:04
ℹ Compiled plugins/client.mjs in 3808.14ms                           01:31:04
app.vue:16:30 - error TS18048: '__VLS_ctx.myState' is possibly 'undefined'.

16 
   

app.vue:16:30 - error TS18048: '__VLS_ctx.myState.arrayState' is possibly 'undefined'.

16 
   

node_modules/nuxt-time/dist/runtime/components/NuxtTime.vue:3:28 - error TS2307: Cannot find module '#build/nuxt-time-script.mjs' or its corresponding type declarations.

3 
  


Found 3 errors in 2 files.

Errors  Files
     2  app.vue:16
     1  node_modules/nuxt-time/dist/runtime/components/NuxtTime.vue:3
@so1ve
Copy link
Member

so1ve commented Apr 6, 2024

Duplicate of #4209

@so1ve so1ve marked this as a duplicate of #4209 Apr 6, 2024
@so1ve so1ve closed this as not planned Won't fix, can't repro, duplicate, stale Apr 6, 2024
@so1ve so1ve added the duplicate This issue or pull request already exists label Apr 6, 2024
@johnsoncodehk johnsoncodehk added the good reproduction ✨ This issue provides a good reproduction, we will be able to investigate it first label Apr 6, 2024
@kingychiu
Copy link
Author

@so1ve How about the issue within node_modules?

@johnsoncodehk
Copy link
Member

@kingychiu Which file should #build/nuxt-time-script.mjs be resolved to? I can't find a nuxt-time-script.mjs file.

@kingychiu
Copy link
Author

hi @johnsoncodehk, that mjs file is used by the nuxt-time package as shown in the reproduction. I think the issue here is more about we should not raise errors from a node module? because I have no control over it.

This error wont be raised in an older version of vue-tsc.

@davidmatter
Copy link
Collaborator

Hey there, as there have been many fixes in the last 2.x versions: Please let us know if you're still encountering this issue. Otherwise kindly close this one, thanks!

@kermanx kermanx marked this as not a duplicate of #4209 Aug 13, 2024
@kermanx
Copy link
Collaborator

kermanx commented Aug 13, 2024

The first reported error is expected. Expression in @click is wrapped in a closure, so that the type narrowing won't work, because myState.arrayState may be changed somewhere else.

The second reported error, I think, is the same as #4249. Let's track it there.

@kermanx kermanx closed this as completed Aug 13, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
duplicate This issue or pull request already exists good reproduction ✨ This issue provides a good reproduction, we will be able to investigate it first need info
Projects
None yet
Development

No branches or pull requests

5 participants