Typesafe injections #10447
-
I am using Vue with <script setup> and typescript. It (for some reason) works! What i wasted hours of my live is the reason why it works despite all the warnings of my IDE. I could ignore the warnings as long as it works but i dont think this is good practise. So here is the code ( i will only post the snippets that are important in my opinion. Just in case i missed something i will post the complete code at the very end of this post): App.vue:
TheBar.vue:
Now comes the fun part(keep in mind, the website just works as intended, its the IDE thats going on my nerves): This is how my watch looks like: i have no idea what it wants from me. Those are the sources i researched so far, all without any help: https://stackoverflow.com/questions/57722093/no-overload-matches-this-call-type-string-is-not-assignable-to-type-signals Here are my questions:
I also tried one of the solutions of the provided links, using InjectionKey (whereas i cannot full understand why i should define and import a complete Interface just for a simple number-type: keys.ts:
App.vue:
TheBar.vue:
Ironicly, after using this fancy InjectionKey, the "animation" of the bar does not work anymore^^. Im at the end of my ideas, let me know what i missed please. The complete code: App.vue:
TheBar.vue:
|
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 4 replies
-
Your problems, in order:
There's likely more details you missed, but those are the important ones, I think. The easiest solution to you issues likely looks like this:
|
Beta Was this translation helpful? Give feedback.
firstElementChild could be an element that does not have this property.
So you would need to tell TS that it's an element that does. Not really related to Vue, rather TS types for the DOM