-
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
Extra generic parameters incorrectly make generic types compatible #41553
Comments
I did not read correctly and was mistaken. |
I believe Y is not needed to cause a structural difference since the class In any case, adding a field of type Y to // Not ok
interface I2<X, Y> {
m2: NotOk2<X, Y>;
}
class NotOk2<X, Y> {
constructor(public x: X, public y: Y) {}
fNotOk2(i2: I2<X, Y>) { i2 = i2; }
}
// !!! Type-checks but should not
const notOk2: NotOk2<string, string> = new NotOk2(0, 0); Because // !!! Type-checks but should not
const notOk: NotOk<string, string> = new NotOk(0);
// !!! undefined
console.log(notOk.x.length); |
You're right, I misread the code. This really seems strange.
Interestingly the error shows up when you remove the |
Yes, |
See #39947 - this is fixed in the nightly build |
TypeScript Version: 4.0.5
Search Terms:
generic, incorrect, assignable, multiple, multi, two, parameter, compatible, unsound, unsafe
Expected behavior:
The type
NotOk<number, number>
below should not be assignable toNotOk<string, string>
Actual behavior:
It is.
Code
Playground Link: Provided
Related Issues:
Somewhat related: #30634, #31006
Extra:
The interface
I2
is needed for when inlined the type-checker fails correctly:However, this behavior could simply be due to a limitation of the unification mechanism used by the type checker.
The text was updated successfully, but these errors were encountered: