language-tools
language-tools copied to clipboard
Unexpected type errors with vue-tsc 2.0.10
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
Duplicate of https://github.com/vuejs/language-tools/issues/4209
@so1ve How about the issue within node_modules?
@kingychiu Which file should #build/nuxt-time-script.mjs
be resolved to? I can't find a nuxt-time-script.mjs
file.
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
.
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!
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.