-
Notifications
You must be signed in to change notification settings - Fork 12.8k
keyof never
should be never
#33025
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Comments
Should it though ? declare let o: never;
let v1 = o[""]
let v2 = o[1]
let v3 = o[Symbol()] |
I wouldn't expect |
It some sense, it doesn't matter. |
If one reasons that |
@jcalz great point. The dual of that would actually be more important -- if |
It's a correct upper bound on If we take it as an axiom that But why not apply union simplification first? So You would still get results consistent with current behaviour but For So, perform intersection simplification to get You would still get results consistent with current behaviour but I'm not invested in changing the behavior of But I guess there's also And |
I guess it's that vacuous truth thing.
When
So, all keys Whereas for Okay, it all makes sense to me now. Thanks for the replies! |
Yep, contravariance (w.r.t. It is a bit odd though in that you can't actually index a |
FYI, for anyone reading: #30753 for context - back after we introduced The current behavior of Suppose I have an object, |
Or just the principle of explosion: |
I still don't get the motivation behind this design, but it seemes like a complicated area. I agree that there may be a reason for current behavior. However, I got specific scenario in mind which lead me here and this is why I think the current behavior is more broken. In short, I got To fix this I need to replace line 16 with line 17. The difference is only syntax, but it lead to opposite behaviors. To fix this behavior I need to copy-paste logic. The difference is subtle, but it might took some time to track this down in complex codebases. I expected TF type to be |
@RyanCavanaugh i honestly could never remember nor understand what those words meant until this diagram. offtopic, but thank you for this |
@AnyhowStep food for thought: your logic would make complete sense if type KeyOf<T> = T extends unknown ? keyof T : never Then you get the behavior you are expecting:
|
TypeScript Version: 3.5.1
Search Terms:
keyof never
Code
Expected behavior:
keyof never
should benever
Actual behavior:
keyof never
isstring|number|symbol
Intuitively, to me, if no values inhabit
never
, then the set of keys is the empty set (alsonever
).Playground Link:
Playground
Related Issues:
Searching "keyof never" brought up 400+ total results, so...
The text was updated successfully, but these errors were encountered: