-
Notifications
You must be signed in to change notification settings - Fork 12.9k
Strange behavior on coercing typeof T
to generic constructor interface
#8166
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
Playing with the repro, this really looks like a bug to me. I can't see any reason this should happen. I suspect the issue is we're not properly finding the anonymous constructor in |
The example I gave @sandersn for why I consider this a bug interface Constructor<T> {
new(...args): T;
}
class A<T> { }
class B<T> extends A<T> {
b: T;
// This line shouldn't do anything, but its presence removes the error
// constructor() {super(); }
}
var c:Constructor<B<boolean>> = B; // error here |
I agree with Ryan. Looking at the error, I imagine that in the inherited constructor for |
Maybe. So far I've tracked it back to that the construct signature for the generic I don't understand what the meaning of |
I think it is the instantiation target. Suppose it was
Calling getSignatureInstantiation will make A's signature the target. I think I am right about this. |
Hmm. If I understand your hypothesis, it's that the signature that B inherits from A should have its return type replaced, but does not. However, I can see that If Renamed Reprointerface Constructor<T> {
new(...args: any[]): T;
prototype: T;
}
class A<U> { a: U; }
class B<V> extends A<V> { b: V; }
var c:Constructor<B<boolean>> = B; // error here |
I have a feeling that the bug has to do with this line in
Because the signature in B has a target, it erases the target, but forgets about the changed return type. So you may be on the right track about not following the target chain. I think that signatures that get instantiated multiple times should be taken care of in One other thing to look at is in if (signature.target) {
type = instantiateType(getReturnTypeOfSignature(signature.target), signature.mapper);
} |
So first I tried the nuclear option: I deleted the target-following code in @ahejlsberg, can you take a look at this? @mhegazy says that he thinks you wrote this code. And I don't know enough about instantiation in general to understand single vs multiple instantiation, etc. |
I took a look and the issue does indeed appear to be caused by the target-following code in So, summing up, I'm fine with removing the target-following code and I just confirmed that our tests all run fine. |
I agree, I can't think of any reason why removing this would cause a problem. |
All right, I'll publish the PR that deletes the target-following code. |
Pull request is up |
Can anyone shed a bit of light on the following behavior
The error is:
I suspect that it is a correct behavior in the current design of the type system, I just don't understand two things:
<any>
@JsonFreeman, @ahejlsberg?
The text was updated successfully, but these errors were encountered: