Vue.js: Data function type is ignored by WebStorm
Hi there,
I migrated to a new setup today, coming from Ubuntu 20.04 LTS to now Ubuntu 22.04 LTS. Both were running the same versions of WebStorm (managed by Snap). However I'm now having issues I did not have before.
I've got an interface called `Data` with a field being a union type `Foo | null`. my data() function is marked to return the Data interface, and has the field set to null. When later trying to assign a Foo type to that field, which is allowed by the type system and compiles fine. WebStorm has different ideas though, giving me `Assigned expression type Foo is not assignable to type null`
What can I do to solve this issue?
WebStorm: 2022.1 build WS-221.5591.52
OpenJDK: 11.0.14.1+1-b2043.45
uname -r: 5.15.0-33-generic
npm -v: 8.5.5
node -v: v17.9.0
vue -V: @vue/cli 5.0.4
Please sign in to leave a comment.
Does invalidating caches (File > Invalidate caches, Invalidate and Restart) help? if it doesn't, please share a complete, self-containing code snippet the issue can be repeated with
Unfortunately it does not. Here is a stripped down snippet: https://pastebin.com/MpWK8JLH
More examples:
foo: string | null in the Data interface, defaulting to null in the data() function, then setting a string will give type "The contents of the string" is not assignable to null.
foo: SomeType | null in the Data interface, defaulting to null in the data() function, after setting the value, or using the ! operator, autocompletion will not suggest field or function names, thinking the type is null. Errors such as 'Unresolved variable' and 'Unresolved method or function' will pop up.
Thanks! Submitted to developers as https://youtrack.jetbrains.com/issue/WEB-56084, please follow it for updates