-
Notifications
You must be signed in to change notification settings - Fork 12.8k
Some information is lost when working with keyof against type arguments #48989
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
Resolving of conditional types is deferred when generic type arguments are involved. It is not using the type that your argument extends ( |
@MartinJohns, thanks for the quick reply! As you can see further down the code, it does work when used outside of the class, but I guess conditional types have been resolved by then. I understand that there's a lot of underlying complexity and reasoning for all this, but is there a way around this? Is this something that might be "improved" in a future version? Or is it just not possible to achieve? I am not originally the author of the |
Yes, in that case you're not dealing with an unbound generic type anymore, but with a concrete one. The compiler now knows what type
Who knows when Anders will cast his magic and improve the language in unpredictable ways. But what you're attempting is unsound behaviour. You're assuming That the key And from this brief example I can't see why you'd need a generic type anyway, when you can just use |
There's no way for TS to establish the higher-order relationship between what goes into |
Got around to logging #48992 |
Bug Report
🔎 Search Terms
Hard topic to search for IMO, but I tried phrases like
typescript generic interface lose type information
and I only found similar issues but not related.🕗 Version & Regression Information
I was having trouble using version 4.5.5 (that we're currently using), but I could also reproduce it in the latest version available in the playground (4.6.2). I checked versions back to 3.3.3 in the playground and they all reported the same issue.
⏯ Playground Link
Playground link with relevant code
💻 Code
🙁 Actual behavior
I lose some type information within the super-class when working with a generic argument.
🙂 Expected behavior
I feel like it should be able to maintain type information here.
The text was updated successfully, but these errors were encountered: