-
Notifications
You must be signed in to change notification settings - Fork 12.6k
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
Relations based on variance markers do not take into account parameters used as key types. #29698
Comments
The cause of this is #27804. With that PR we started measuring variances for type aliases to object and conditional types. The variance measuring logic determines that @weswigham Perhaps we should exclude aliases to mapped types from the variance measuring shortcut? |
Thanks for looking into this @ahejlsberg. I guess the difference I'm seeing when using two different aliases is because variance measurements are not shared across different aliases of identical types?
This seems a similar problem to #28798. I guess the underlying problem is that the semantics of Would another---albeit more costly ---solution be to have a key relation that interprets key types into their value type equivalent before using the value relation? |
Also see #29393 which appears to be an effect of variance measuring for aliased types. |
I changed the title to something that is hopefully closer to the actual issue. Feel free to change if it is misleading. My understanding now, after your comments and reading the source, is that a contravariant marker is inferred for the parameter isRelatedTo(getConstraintTypeFromMappedType(target), getConstraintTypeFromMappedType(source), reportErrors)) but this does not take into account the fact that Would it be completely unreasonably to collect uses as key types along with variances, and use that to correctly determine when and how two instantiations of Am I right in saying that this is going to be a problem if #26797 lands? Where you could have: interface Record<K extends string,T> {
[x: K]: T
} |
TypeScript Version: 3.3
Code
Playground Link: link
Related Issues: #28798
The text was updated successfully, but these errors were encountered: