TypeScript Type Error when hover in a variable Follow
I am writing a type to get the last element type of a tuple, see on type-challenges: https://github.com/type-challenges/type-challenges/blob/main/questions/00015-medium-last/README.md
And the IDE get the wrong type. When I hover to the variable, it shows never type. It's completely wrong and it makes me very confuse.
type arr = ['a', 'c']
type Last<T> = T extends [...any, infer L] ? L : never
type tail = Last<arr1> // it should be 'c', but it give never
// But when I assign the type to a variable, it works
const a: tail = 'c' // Hover to a, the type is 'c', correct.
I try it on typescript Playground, and vscode, it all work. Only Webstorm got the wrong answer. Similar questions appear many times. And I close webstorm and restart it, it doesn't work as the same.
Is there a issue for that?
Please sign in to leave a comment.
The type is correctly inferred for me - here are the results shown on hover and Ctrl+hover:
what IDE version do you use?
Sorry I don't find a button to reply your comment so I write a comment down here, hope you can see it.
I use WebStorm 2022.2.2, Apple Silicon Version.
The result down here.
you can see that, the type is never. But I assign a variable to this type, it works. It should be '3' type.
Well, when I press the command key and hover to the type, it works. The picture is down here.
It works but only when I press the command key and hover to the type.
But I still feel sad about it..I don't want to press another key when I need to check the type..
Could you check if you can reproduce the issue in a new project using the code snippet from your previous post? What does your tsconfig.json look like?
I check again the code.
It's OK when the `arr` type is only two members. More than two is not OK!!
The code I write is type arr = [1, 2], only two elements in the tuple type. When it comes to three or more, It won't work.
You could check it on your WebStorm, it's not about the tsconfig.json, it's just wrong..
Unless I press the command key and hover to the variable, It works.
Thanks for clarification; it's a known issue unfortunately, please follow https://youtrack.jetbrains.com/issue/WEB-55036/Wrong-initial-type-when-using-conditional-types-with-spread for updates