language-tools icon indicating copy to clipboard operation
language-tools copied to clipboard

Unexpected type errors with vue-tsc 2.0.10

Open kingychiu opened this issue 3 months ago • 4 comments

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

kingychiu avatar Apr 05 '24 17:04 kingychiu

Duplicate of https://github.com/vuejs/language-tools/issues/4209

so1ve avatar Apr 06 '24 14:04 so1ve

@so1ve How about the issue within node_modules?

kingychiu avatar Apr 06 '24 21:04 kingychiu

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

johnsoncodehk avatar Apr 07 '24 00:04 johnsoncodehk

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.

kingychiu avatar Apr 08 '24 08:04 kingychiu