-
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
Relax the rule on the compiler side that all declarations have the same constraint #20018
Comments
Big fan 👋 👋 👋 |
Does that mean that, when a constraint is not specified, that it should "inherit" the most specific constraint found elsewhere? Or does that only apply on instantiation? |
this has nothign to do with instantiations.. it is about declarations.. interface A<T> {}
interface A<T extends number> {} today this is an error. this issue is to relax the check and treat it as: interface A<T extends number> {}
interface A<T extends number> {} Also note that mismatched constraints is still an error: interface B<T extends number> {}
interface B<T extends string> {} |
Easy PR for anyone who wants to take it, or we can pick it up in a bit |
Where would one look to start tackling this? |
@RichiCoder1 there's a function |
fix #20018, allow skip constraint when merging interfaces
thanks @HerringtonDarkholme ! |
Originally reported in #14840
Consider
WeakSet
for instance.. today it is defined asinterface WeakSet <T> {...}
. This is incorrect, as it allows for patterns likeconst s = new WeakSet<string>(); s.add("foo");
which throws at runtime; the correct definition forWeakSet
isinterface WeakSet<T extends object> { .. }
.Changing this definition will cause errors in files that redefine
WeakSet
to add additional members to it.The proposal here is to allow type parameter declarations to skip constraints. conflicting constraints should still be reported as errors.
The text was updated successfully, but these errors were encountered: